Class: SpreeCmCommissioner::Transit::RouteStop
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Transit::RouteStop
- Defined in:
- lib/spree_cm_commissioner/transit/route_stop.rb
Constant Summary collapse
- STOP_TYPES =
%i[branch stop].freeze
Instance Attribute Summary collapse
-
#location_id ⇒ Object
Returns the value of attribute location_id.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vendor_place ⇒ Object
Returns the value of attribute vendor_place.
-
#vendor_place_id ⇒ Object
Returns the value of attribute vendor_place_id.
Class Method Summary collapse
Instance Method Summary collapse
- #branch? ⇒ Boolean
- #errors ⇒ Object
-
#initialize(options = {}) ⇒ RouteStop
constructor
A new instance of RouteStop.
- #stop? ⇒ Boolean
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ RouteStop
Returns a new instance of RouteStop.
7 8 9 10 11 12 13 14 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 7 def initialize( = {}) @location_id = [:location_id]&.to_i @type = [:type]&.to_sym @sequence = [:sequence]&.to_i # vendor place is either stop or branch @vendor_place_id = [:vendor_place_id]&.to_i end |
Instance Attribute Details
#location_id ⇒ Object
Returns the value of attribute location_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 3 def location_id @location_id end |
#sequence ⇒ Object
Returns the value of attribute sequence.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 3 def sequence @sequence end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 3 def type @type end |
#vendor_place ⇒ Object
Returns the value of attribute vendor_place.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 3 def vendor_place @vendor_place end |
#vendor_place_id ⇒ Object
Returns the value of attribute vendor_place_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 3 def vendor_place_id @vendor_place_id end |
Class Method Details
.from_hash(hash) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 16 def self.from_hash(hash) hash = hash.symbolize_keys new( location_id: hash[:location_id], vendor_place_id: hash[:vendor_place_id], type: hash[:type], sequence: hash[:sequence] ) end |
Instance Method Details
#branch? ⇒ Boolean
36 37 38 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 36 def branch? @type == :branch end |
#errors ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 48 def errors @errors ||= [] @errors.clear @errors << 'location_id is required' if @location_id.blank? @errors << 'vendor_place_id is required' if @vendor_place_id.blank? @errors << 'type is required' if @type.blank? @errors << 'type must be :branch or :stop' if @type.present? && STOP_TYPES.exclude?(@type) @errors << 'sequence is required' if @sequence.nil? @errors end |
#stop? ⇒ Boolean
40 41 42 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 40 def stop? @type == :stop end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 27 def to_h { location_id: @location_id, vendor_place_id: @vendor_place_id, type: @type, sequence: @sequence } end |
#valid? ⇒ Boolean
44 45 46 |
# File 'lib/spree_cm_commissioner/transit/route_stop.rb', line 44 def valid? errors.empty? end |