Skip to content

Commit

Permalink
Работа с файлом
Browse files Browse the repository at this point in the history
  • Loading branch information
1e-to committed Sep 30, 2018
1 parent 60344c8 commit 18095e1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'csv'

class Text

def opens()
@fh = open "test.csv"
@mas = []
while (line = @fh.gets)
@mas.insert(@mas.length, line.to_f)
end
@fh.close
return @mas
end

def choice()
puts "Enter what you need to count (x-max, n-min, a-average, d-dispersion)"
@n = gets.chomp
end

def match()

@avr = @mas.reduce(:+) / @mas.length
@dis = 0
case @n
when "x"
@mas.max
when "n"
@mas.min
when "a"
@avr
when "d"
@mas.each do |i|
@dis = @dis + (i - @avr) * 2
end
@dis / (@mas.length - 1)
end
end

def out
puts match
end

end

txt = Text.new
txt.opens
txt.choice
txt.match
txt.out

0 comments on commit 18095e1

Please sign in to comment.