Class: Archivo
- Inherits:
-
Object
- Object
- Archivo
- Defined in:
- lib/csv_reader.rb
Instance Attribute Summary collapse
-
#archivo ⇒ Object
Returns the value of attribute archivo.
Instance Method Summary collapse
- #cant_repetidos ⇒ Object
-
#initialize(csv_file_name) ⇒ Archivo
constructor
A new instance of Archivo.
- #total_value_in_stock ⇒ Object
Constructor Details
#initialize(csv_file_name) ⇒ Archivo
Returns a new instance of Archivo.
7 8 9 10 11 12 13 14 15 |
# File 'lib/csv_reader.rb', line 7 def initialize(csv_file_name) @libro_del_archivo = Enumerator.new do |y| archivo = CSV.foreach(csv_file_name, headers: true).each loop do row = archivo.next y << Libro.new(row[0], row[1], row[2]) end end end |
Instance Attribute Details
#archivo ⇒ Object
Returns the value of attribute archivo.
5 6 7 |
# File 'lib/csv_reader.rb', line 5 def archivo @archivo end |
Instance Method Details
#cant_repetidos ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/csv_reader.rb', line 25 def cant_repetidos repeticiones = Hash.new(0) loop do repeticiones[@libro_del_archivo.next.isbn] += 1 end repeticiones end |
#total_value_in_stock ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/csv_reader.rb', line 17 def total_value_in_stock sum = 0.0 loop do sum += @libro_del_archivo.next.price end sum.truncate(2) end |