Class: Ns::Trip
Instance Attribute Summary collapse
-
#allow_hsl ⇒ Object
Returns the value of attribute allow_hsl.
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#from ⇒ Object
Returns the value of attribute from.
-
#to ⇒ Object
Returns the value of attribute to.
-
#via ⇒ Object
Returns the value of attribute via.
-
#year_card ⇒ Object
Returns the value of attribute year_card.
Instance Method Summary collapse
- #departure? ⇒ Boolean
- #formatted_time ⇒ Object
- #time ⇒ Object
- #travel_options ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Methods included from Model
Instance Attribute Details
#allow_hsl ⇒ Object
Returns the value of attribute allow_hsl.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def allow_hsl @allow_hsl end |
#arrival ⇒ Object
Returns the value of attribute arrival.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def arrival @arrival end |
#departure ⇒ Object
Returns the value of attribute departure.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def departure @departure end |
#from ⇒ Object
Returns the value of attribute from.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def from @from end |
#to ⇒ Object
Returns the value of attribute to.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def to @to end |
#via ⇒ Object
Returns the value of attribute via.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def via @via end |
#year_card ⇒ Object
Returns the value of attribute year_card.
5 6 7 |
# File 'lib/ns/trip.rb', line 5 def year_card @year_card end |
Instance Method Details
#departure? ⇒ Boolean
35 36 37 |
# File 'lib/ns/trip.rb', line 35 def departure? !departure.nil? && !departure.to_s.strip.empty? end |
#formatted_time ⇒ Object
27 28 29 |
# File 'lib/ns/trip.rb', line 27 def formatted_time time.iso8601 end |
#time ⇒ Object
31 32 33 |
# File 'lib/ns/trip.rb', line 31 def time [ departure, arrival ].compact.first || Time.now end |
#travel_options ⇒ Object
57 58 59 |
# File 'lib/ns/trip.rb', line 57 def @travel_options ||= response. end |
#valid? ⇒ Boolean
39 40 41 42 43 |
# File 'lib/ns/trip.rb', line 39 def valid? validate! rescue false end |
#validate! ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ns/trip.rb', line 45 def validate! if !arrival_present? && !departure_present? raise "You should specify a departure or arrival time." end if (arrival_present? && arrival.class != Time) || (departure_present? && departure.class != Time) raise "Departure or arrival time should be an instance of Time" end true end |