Class: Generador
- Inherits:
-
Object
- Object
- Generador
- Defined in:
- lib/csv_generator.rb
Instance Attribute Summary collapse
-
#cantidad ⇒ Object
Returns the value of attribute cantidad.
-
#nombre_archivo ⇒ Object
Returns the value of attribute nombre_archivo.
Instance Method Summary collapse
- #date_gen ⇒ Object
- #file_gen ⇒ Object
-
#initialize(nombre, cantidad) ⇒ Generador
constructor
A new instance of Generador.
- #isbn_gen ⇒ Object
- #price_gen ⇒ Object
Constructor Details
#initialize(nombre, cantidad) ⇒ Generador
Returns a new instance of Generador.
8 9 10 11 |
# File 'lib/csv_generator.rb', line 8 def initialize(nombre, cantidad) @nombre_archivo = nombre @cantidad = cantidad end |
Instance Attribute Details
#cantidad ⇒ Object
Returns the value of attribute cantidad.
6 7 8 |
# File 'lib/csv_generator.rb', line 6 def cantidad @cantidad end |
#nombre_archivo ⇒ Object
Returns the value of attribute nombre_archivo.
6 7 8 |
# File 'lib/csv_generator.rb', line 6 def nombre_archivo @nombre_archivo end |
Instance Method Details
#date_gen ⇒ Object
17 18 19 20 21 |
# File 'lib/csv_generator.rb', line 17 def date_gen from = 0.0 to = Time.now Time.at(from + rand * (to.to_f - from.to_f)).strftime('%d/%m/%Y') end |
#file_gen ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/csv_generator.rb', line 27 def file_gen CSV.open(@nombre_archivo, 'w+', headers:['Date', 'ISBN', 'Amount'], write_headers: true) do |archivo| (@cantidad * 1_000_000).times do archivo << [date_gen.to_s, isbn_gen.to_s, price_gen] end end end |
#isbn_gen ⇒ Object
13 14 15 |
# File 'lib/csv_generator.rb', line 13 def isbn_gen "#{rand.to_s[2..4]}-#{rand.to_s[2..2]}-#{rand.to_s[2..8]}-#{rand.to_s[2..2]}-#{rand.to_s[2..2]}" end |
#price_gen ⇒ Object
23 24 25 |
# File 'lib/csv_generator.rb', line 23 def price_gen rand(0.0..99.99).truncate(2) end |