Class: Howard::TimeToArrival

Inherits:
Object
  • Object
show all
Defined in:
lib/howard/time_to_arrival.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arrival) ⇒ TimeToArrival

Returns a new instance of TimeToArrival.



5
6
7
# File 'lib/howard/time_to_arrival.rb', line 5

def initialize(arrival)
  @arrival = arrival
end

Instance Attribute Details

#arrivalObject (readonly)

Returns the value of attribute arrival.



3
4
5
# File 'lib/howard/time_to_arrival.rb', line 3

def arrival
  @arrival
end

Instance Method Details

#minutesObject



9
10
11
# File 'lib/howard/time_to_arrival.rb', line 9

def minutes
  (arrival.arrival_time.to_i - arrival.prediction_time.to_i) / 60
end

#to_s(format = "%d min") ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/howard/time_to_arrival.rb', line 13

def to_s(format = "%d min")
  if arrival.delayed?
    "Delayed"
  elsif arrival.approaching?
    "Due"
  else
    format % minutes
  end
end