Class: Centra::OrderData
- Inherits:
-
Object
- Object
- Centra::OrderData
- Includes:
- Enumerable
- Defined in:
- lib/centra/order_data.rb
Defined Under Namespace
Classes: AnonValue
Instance Method Summary collapse
- #anonymize! ⇒ Object
- #each(&block) ⇒ Object
- #each_order(&block) ⇒ Object
- #header ⇒ Object
-
#initialize(file) ⇒ OrderData
constructor
A new instance of OrderData.
- #inspect ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(file) ⇒ OrderData
Returns a new instance of OrderData.
10 11 12 13 |
# File 'lib/centra/order_data.rb', line 10 def initialize(file) @csv = parse_csv(file) @rows = nil end |
Instance Method Details
#anonymize! ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/centra/order_data.rb', line 31 def anonymize! cache = AnonValue.new rows.each do |row| email = row.delivery_email # make sure the same email gets the same anonymized email row.delivery_email = cache.value_for(email) { "#{SecureRandom.uuid}@example.com" } end end |
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/centra/order_data.rb', line 23 def each(&block) rows.each(&block) end |
#each_order(&block) ⇒ Object
27 28 29 |
# File 'lib/centra/order_data.rb', line 27 def each_order(&block) rows.each { |row| yield(Order.new(row)) } end |
#header ⇒ Object
15 16 17 |
# File 'lib/centra/order_data.rb', line 15 def header @csv.header end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/centra/order_data.rb', line 41 def inspect "#<CentraData:#{"0x00%x" % (object_id << 1)}(header: #{header})" end |
#rows ⇒ Object
19 20 21 |
# File 'lib/centra/order_data.rb', line 19 def rows @csv.rows end |