class Centra::OrderData

Public Class Methods

new(file) click to toggle source
# File lib/centra/order_data.rb, line 10
def initialize(file)
  @csv = parse_csv(file)
  @rows = nil
end

Public Instance Methods

anonymize!() click to toggle source
# 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) click to toggle source
# File lib/centra/order_data.rb, line 23
def each(&block)
  rows.each(&block)
end
each_order() { |order| ... } click to toggle source
# File lib/centra/order_data.rb, line 27
def each_order(&block)
  rows.each { |row| yield(Order.new(row)) }
end
header() click to toggle source
# File lib/centra/order_data.rb, line 15
def header
  @csv.header
end
inspect() click to toggle source
# File lib/centra/order_data.rb, line 41
def inspect
  "#<CentraData:#{"0x00%x" % (object_id << 1)}(header: #{header})"
end
rows() click to toggle source
# File lib/centra/order_data.rb, line 19
def rows
  @csv.rows
end

Private Instance Methods

parse_csv(string) click to toggle source
# File lib/centra/order_data.rb, line 47
def parse_csv(string)
  HoneyFormat::CSV.new(string, header_converter: Centra::CSVHeaderConverter)
end