Class: CsvReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_reader_csv.rb

Instance Method Summary collapse

Constructor Details

#initializeCsvReader

Returns a new instance of CsvReader.



10
11
12
13
# File 'lib/ruby_reader_csv.rb', line 10

def initialize
    @hash ={}
    @total = 0.0
end

Instance Method Details

#number_of_each_isbnObject



29
30
31
# File 'lib/ruby_reader_csv.rb', line 29

def number_of_each_isbn
    return @hash
end

#read_in_csv_data(csv_file_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_reader_csv.rb', line 14

def read_in_csv_data(csv_file_name)
    CSV.foreach(csv_file_name, headers: true) do |row|
        #sumo el precio al total
        @total += Float(row["Amount"])
        #si el ISBN ya esta en el hash le sumo una unidad mas y si no esta lo agrego cin un valor 1
        if @hash.has_key?((row["ISBN"]).to_sym)               
            @hash[row["ISBN"].to_sym] =  @hash[row["ISBN"].to_sym] +1 
        else
            @hash[row["ISBN"].to_sym] = 1
        end
    end
end

#total_value_in_stockObject



26
27
28
# File 'lib/ruby_reader_csv.rb', line 26

def total_value_in_stock    
  return @total
end