Class: LabelMe::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/label_me/order.rb,
lib/label_me/order/customer.rb,
lib/label_me/order/line_item.rb,
lib/label_me/order/recipient.rb

Defined Under Namespace

Classes: Customer, LineItem, Recipient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Order

Returns a new instance of Order.



6
7
8
9
10
11
12
13
14
# File 'lib/label_me/order.rb', line 6

def initialize(row)
  @number              = row.order_id.to_i
  @order_date          = row.order_date
  @paid                = row.paid?
  @shipping_charge     = row.total_shipping_charge
  @message_card_charge = row.total_message_card_charge
  @customer            = LabelMe::Order::Customer.new(row)
  @recipients          = [LabelMe::Order::Recipient.new(row)]
end

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



20
21
22
# File 'lib/label_me/order.rb', line 20

def customer
  @customer
end

#message_card_chargeObject

Returns the value of attribute message_card_charge.



19
20
21
# File 'lib/label_me/order.rb', line 19

def message_card_charge
  @message_card_charge
end

#numberObject

Returns the value of attribute number.



16
17
18
# File 'lib/label_me/order.rb', line 16

def number
  @number
end

#order_dateObject

Returns the value of attribute order_date.



17
18
19
# File 'lib/label_me/order.rb', line 17

def order_date
  @order_date
end

#recipientsObject

Returns the value of attribute recipients.



21
22
23
# File 'lib/label_me/order.rb', line 21

def recipients
  @recipients
end

#shipping_chargeObject

Returns the value of attribute shipping_charge.



18
19
20
# File 'lib/label_me/order.rb', line 18

def shipping_charge
  @shipping_charge
end

Instance Method Details

#===(other) ⇒ Object



39
40
41
# File 'lib/label_me/order.rb', line 39

def ===(other)
  self.number == other.number
end

#paid?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/label_me/order.rb', line 23

def paid?
  @paid
end

#to_hashObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/label_me/order.rb', line 27

def to_hash
  {
    number:                number,
    order_date:            order_date,
    paid?:                 paid?,
    shipping_charge:       shipping_charge,
    message_card_charge:   message_card_charge,
    customer_attributes:   customer.to_hash,
    recipients_attributes: recipients.map(&:to_hash),
  }
end