Class: Ns::Trip

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/ns/trip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Model

#initialize

Instance Attribute Details

#allow_hslObject

Returns the value of attribute allow_hsl.



5
6
7
# File 'lib/ns/trip.rb', line 5

def allow_hsl
  @allow_hsl
end

#arrivalObject

Returns the value of attribute arrival.



5
6
7
# File 'lib/ns/trip.rb', line 5

def arrival
  @arrival
end

#departureObject

Returns the value of attribute departure.



5
6
7
# File 'lib/ns/trip.rb', line 5

def departure
  @departure
end

#fromObject

Returns the value of attribute from.



5
6
7
# File 'lib/ns/trip.rb', line 5

def from
  @from
end

#toObject

Returns the value of attribute to.



5
6
7
# File 'lib/ns/trip.rb', line 5

def to
  @to
end

#viaObject

Returns the value of attribute via.



5
6
7
# File 'lib/ns/trip.rb', line 5

def via
  @via
end

#year_cardObject

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

Returns:

  • (Boolean)


35
36
37
# File 'lib/ns/trip.rb', line 35

def departure?
  !departure.nil? && !departure.to_s.strip.empty?
end

#formatted_timeObject



27
28
29
# File 'lib/ns/trip.rb', line 27

def formatted_time
  time.iso8601
end

#timeObject



31
32
33
# File 'lib/ns/trip.rb', line 31

def time
  [ departure, arrival ].compact.first || Time.now
end

#travel_optionsObject



57
58
59
# File 'lib/ns/trip.rb', line 57

def travel_options
  @travel_options ||= response.travel_options
end

#valid?Boolean

Returns:

  • (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