Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.49 KB | None | 0 0
  1. require 'csv'
  2.  
  3. class FileReader
  4.    
  5.     attr_reader :path
  6.    
  7.     def initialize(path)
  8.         @path = path
  9.     end
  10.    
  11.     def process()
  12.         weth = []
  13.  
  14.         CSV.foreach('task.csv', converters: :numeric) do |row|
  15.             puts row.inspect
  16.             weth << row[1]
  17.         end
  18.        
  19.         a = weth.inject { |sum, n| sum + n }
  20.        
  21.         puts 'Average temperature weather is'
  22.         p a
  23.     end
  24. end
  25.  
  26. reader = FileReader.new("task.csv")
  27. reader.process()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement