Class: Workarea::Fulfillment::Package
- Inherits:
-
Object
- Object
- Workarea::Fulfillment::Package
- Defined in:
- app/models/workarea/fulfillment/package.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#tracking_number ⇒ Object
readonly
Returns the value of attribute tracking_number.
Class Method Summary collapse
Instance Method Summary collapse
- #created_at ⇒ Object
- #events_by_item ⇒ Object
-
#initialize(tracking_number, events = []) ⇒ Package
constructor
A new instance of Package.
- #updated_at ⇒ Object
Constructor Details
#initialize(tracking_number, events = []) ⇒ Package
Returns a new instance of Package.
22 23 24 25 |
# File 'app/models/workarea/fulfillment/package.rb', line 22 def initialize(tracking_number, events = []) @tracking_number = tracking_number @events = events end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
20 21 22 |
# File 'app/models/workarea/fulfillment/package.rb', line 20 def events @events end |
#tracking_number ⇒ Object (readonly)
Returns the value of attribute tracking_number.
20 21 22 |
# File 'app/models/workarea/fulfillment/package.rb', line 20 def tracking_number @tracking_number end |
Class Method Details
.create(events) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/workarea/fulfillment/package.rb', line 4 def self.create(events) tracking_numbers = events .select { |e| e.status == 'shipped' } .map { |e| e.data['tracking_number'] } .uniq tracking_numbers.map do |tracking_number| matching_events = events.select do |event| event.status == 'shipped' && event.data['tracking_number'] == tracking_number end Package.new(tracking_number, matching_events) end end |
Instance Method Details
#created_at ⇒ Object
31 32 33 |
# File 'app/models/workarea/fulfillment/package.rb', line 31 def created_at sorted_event_creation_dates.first end |
#events_by_item ⇒ Object
27 28 29 |
# File 'app/models/workarea/fulfillment/package.rb', line 27 def events_by_item @events.group_by(&:order_item_id) end |
#updated_at ⇒ Object
35 36 37 |
# File 'app/models/workarea/fulfillment/package.rb', line 35 def updated_at sorted_event_creation_dates.last end |