Class: SpreeCmCommissioner::Transit::Leg
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Transit::Leg
- Defined in:
- lib/spree_cm_commissioner/transit/leg.rb
Instance Attribute Summary collapse
-
#boarding_trip_stop_id ⇒ Object
Returns the value of attribute boarding_trip_stop_id.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#drop_off_trip_stop_id ⇒ Object
Returns the value of attribute drop_off_trip_stop_id.
-
#seat_selections ⇒ Object
Returns the value of attribute seat_selections.
-
#trip_id ⇒ Object
Returns the value of attribute trip_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Leg
constructor
A new instance of Leg.
- #quantity ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Leg
Returns a new instance of Leg.
5 6 7 8 9 10 11 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 5 def initialize( = {}) @direction = [:direction] @trip_id = [:trip_id] @boarding_trip_stop_id = [:boarding_trip_stop_id] @drop_off_trip_stop_id = [:drop_off_trip_stop_id] @seat_selections = [:seat_selections] || [] end |
Instance Attribute Details
#boarding_trip_stop_id ⇒ Object
Returns the value of attribute boarding_trip_stop_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 3 def boarding_trip_stop_id @boarding_trip_stop_id end |
#direction ⇒ Object
Returns the value of attribute direction.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 3 def direction @direction end |
#drop_off_trip_stop_id ⇒ Object
Returns the value of attribute drop_off_trip_stop_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 3 def drop_off_trip_stop_id @drop_off_trip_stop_id end |
#seat_selections ⇒ Object
Returns the value of attribute seat_selections.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 3 def seat_selections @seat_selections end |
#trip_id ⇒ Object
Returns the value of attribute trip_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 3 def trip_id @trip_id end |
Class Method Details
.from_hash(hash) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 13 def self.from_hash(hash) new( direction: hash[:direction], # outbound / inbound trip_id: hash[:trip_id], boarding_trip_stop_id: hash[:boarding_trip_stop_id], drop_off_trip_stop_id: hash[:drop_off_trip_stop_id], seat_selections: (hash[:seat_selections] || []).map { |seat_selection| SeatSelection.from_hash(seat_selection) } ) end |
Instance Method Details
#quantity ⇒ Object
23 24 25 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 23 def quantity @seat_selections.sum(&:quantity).to_i end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/spree_cm_commissioner/transit/leg.rb', line 27 def to_h { direction: @direction, trip_id: @trip_id, boarding_trip_stop_id: @boarding_trip_stop_id, drop_off_trip_stop_id: @drop_off_trip_stop_id, seat_selections: @seat_selections.map(&:to_h) } end |