class AmazonPurchasesLedger::Order

Constants

OUTPUT_HEADER_ROW

Attributes

order_id[R]

Public Class Methods

new(order_id:, orders_csv:, items_csv:) click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 5
def initialize(order_id:, orders_csv:, items_csv:)
  @order_id = order_id
  @orders_csv = orders_csv
  @items_csv = items_csv
end

Public Instance Methods

complete?() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 11
def complete?
  amount != nil
end
items() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 43
def items
  shipments.flat_map(&:items)
end
memo() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 32
def memo
  shipments.map(&:output_text).join("\n")
end
output_row() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 22
def output_row
  return nil if shipments.any? { |shipment| shipment.total_charged.nil? }
  [
    order_date,
    payment_account,
    amount,
    memo
  ]
end
shipments() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 36
def shipments
  AmazonPurchasesLedger::Shipment::Factory.new(order_id: @order_id,
                                               orders_csv: @orders_csv,
                                               items_csv: @items_csv)
    .shipments
end

Private Instance Methods

amount() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 60
def amount
  return nil if shipments.any? { |shipment| shipment.total_charged.nil? }
  shipments.map { |shipment| shipment.total_charged }
    .sum.to_f.to_s.prepend('$')
end
order_date() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 52
def order_date
  shipment_rows.first[:order_date]
end
payment_account() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 56
def payment_account
  shipment_rows.first[:payment_instrument_type]
end
shipment_rows() click to toggle source
# File lib/amazon_purchases_ledger/order.rb, line 48
def shipment_rows
  @orders_csv.select { |row| row[:order_id] == @order_id }
end