Class: Cornerstore::Shipment

Inherits:
Model::Base show all
Defined in:
lib/cornerstore/api/shipment.rb

Defined Under Namespace

Classes: Resource

Instance Attribute Summary collapse

Attributes inherited from Model::Base

#_id, #_slugs, #parent, #updated_at

Instance Method Summary collapse

Methods inherited from Model::Base

#==, #attributes, #attributes=, #inspect, #method_missing, method_missing, #to_param, #url

Constructor Details

#initialize(attributes = {}, parent = nil) ⇒ Shipment

Returns a new instance of Shipment.



9
10
11
12
13
# File 'lib/cornerstore/api/shipment.rb', line 9

def initialize(attributes = {}, parent=nil)
  self.carrier  = Cornerstore::Carrier.new(attributes.delete('carrier'))
  self.line_item_ids = attributes.delete('shipped_items')
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cornerstore::Model::Base

Instance Attribute Details

#carrierObject

Returns the value of attribute carrier.



2
3
4
# File 'lib/cornerstore/api/shipment.rb', line 2

def carrier
  @carrier
end

#created_atObject Also known as: shipped_at

Returns the value of attribute created_at.



2
3
4
# File 'lib/cornerstore/api/shipment.rb', line 2

def created_at
  @created_at
end

#line_item_idsObject

Returns the value of attribute line_item_ids.



2
3
4
# File 'lib/cornerstore/api/shipment.rb', line 2

def line_item_ids
  @line_item_ids
end

#tracking_numberObject

Returns the value of attribute tracking_number.



2
3
4
# File 'lib/cornerstore/api/shipment.rb', line 2

def tracking_number
  @tracking_number
end

Instance Method Details

#line_itemsObject Also known as: shipped_items



15
16
17
18
# File 'lib/cornerstore/api/shipment.rb', line 15

def line_items
  return [] unless self.parent
  self.parent.line_items.select { |li| self.line_item_ids.include?(li.id) }
end