Class: NextBus::BusTimes
- Inherits:
-
Object
- Object
- NextBus::BusTimes
- Defined in:
- lib/next_bus/bus_times.rb
Instance Attribute Summary collapse
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
-
#initialize(bus_times) ⇒ BusTimes
constructor
A new instance of BusTimes.
- #list ⇒ Object
- #mins_till ⇒ Object
- #next_bus ⇒ Object
Constructor Details
#initialize(bus_times) ⇒ BusTimes
Returns a new instance of BusTimes.
5 6 7 |
# File 'lib/next_bus/bus_times.rb', line 5 def initialize(bus_times) @times = bus_times.sort! end |
Instance Attribute Details
#times ⇒ Object (readonly)
Returns the value of attribute times.
3 4 5 |
# File 'lib/next_bus/bus_times.rb', line 3 def times @times end |
Instance Method Details
#list ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/next_bus/bus_times.rb', line 18 def list temp_times = self.times.dup temp_times << time_now temp_times.sort! index = temp_times.index(time_now) from = times.length - index times[-from..from] if from > 0 end |
#mins_till ⇒ Object
29 30 31 32 |
# File 'lib/next_bus/bus_times.rb', line 29 def mins_till n_bus = next_bus n_bus.to_i - time_now.to_i if n_bus end |
#next_bus ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/next_bus/bus_times.rb', line 9 def next_bus temp_times = self.times.dup temp_times << time_now temp_times.sort! index = temp_times.index(time_now) self.times[index] end |