Class: TravelTime::Transport
- Inherits:
-
Object
- Object
- TravelTime::Transport
- Defined in:
- lib/travel_time/transport.rb
Overview
The Transport class provides a way to set transportation details
Constant Summary collapse
- ALLOWED_DETAILS =
Define allowed details for each transport type
{ 'pt' => %i[walking_time_to_station], 'driving+pt' => %i[walking_time_to_station driving_time_to_station parking_time] }.freeze
- PROTO_TRANSPORT_MAP =
{ pt: { code: 0, url_name: 'pt' }, 'driving+pt': { code: 2, url_name: 'pt' }, driving: { code: 1, url_name: 'driving' }, walking: { code: 4, url_name: 'walking' }, cycling: { code: 5, url_name: 'driving' }, 'driving+ferry': { code: 3, url_name: 'driving+ferry' }, 'cycling+ferry': { code: 6, url_name: 'cycling+ferry' }, 'walking+ferry': { code: 7, url_name: 'walking+ferry' } }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url_name ⇒ Object
readonly
Returns the value of attribute url_name.
Instance Method Summary collapse
- #apply_to_proto(transportation) ⇒ Object
-
#initialize(transport_input) ⇒ Transport
constructor
A new instance of Transport.
-
#validate_details! ⇒ Object
Validate that the provided details are allowed for this transport type.
Constructor Details
#initialize(transport_input) ⇒ Transport
Returns a new instance of Transport.
25 26 27 28 |
# File 'lib/travel_time/transport.rb', line 25 def initialize(transport_input) setup_type_and_details(transport_input) set_transport_info end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/travel_time/transport.rb', line 6 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
6 7 8 |
# File 'lib/travel_time/transport.rb', line 6 def details @details end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/travel_time/transport.rb', line 6 def type @type end |
#url_name ⇒ Object (readonly)
Returns the value of attribute url_name.
6 7 8 |
# File 'lib/travel_time/transport.rb', line 6 def url_name @url_name end |
Instance Method Details
#apply_to_proto(transportation) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/travel_time/transport.rb', line 38 def apply_to_proto(transportation) # Set the base type transportation.type = @code # Apply PublicTransport details - Only for type "pt" (code 0) apply_public_transport_details(transportation) if @code.zero? && @details[:walking_time_to_station] # Apply DrivingAndPublicTransport details - Only for type "driving+pt" (code 2) apply_driving_pt_details(transportation) if @code == 2 transportation end |
#validate_details! ⇒ Object
Validate that the provided details are allowed for this transport type
31 32 33 34 35 36 |
# File 'lib/travel_time/transport.rb', line 31 def validate_details! return if @details.empty? validate_transport_type_supports_details validate_unexpected_details end |