Class: NextBus::BusTimes

Inherits:
Object
  • Object
show all
Defined in:
lib/next_bus/bus_times.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#timesObject (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

#listObject



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_tillObject



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_busObject



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