Class: CycleHire::Journey

Inherits:
Object
  • Object
show all
Defined in:
lib/cycle_hire/journey.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, start_station, end_time, end_station, cost) ⇒ Journey

Returns a new instance of Journey.



4
5
6
7
8
9
10
# File 'lib/cycle_hire/journey.rb', line 4

def initialize(start_time, start_station, end_time, end_station, cost)
  @start_time = start_time
  @start_station = start_station
  @end_time = end_time
  @end_station = end_station
  @cost = cost
end

Instance Attribute Details

#costObject (readonly)

Returns the value of attribute cost.



2
3
4
# File 'lib/cycle_hire/journey.rb', line 2

def cost
  @cost
end

#end_stationObject (readonly)

Returns the value of attribute end_station.



2
3
4
# File 'lib/cycle_hire/journey.rb', line 2

def end_station
  @end_station
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



2
3
4
# File 'lib/cycle_hire/journey.rb', line 2

def end_time
  @end_time
end

#start_stationObject (readonly)

Returns the value of attribute start_station.



2
3
4
# File 'lib/cycle_hire/journey.rb', line 2

def start_station
  @start_station
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



2
3
4
# File 'lib/cycle_hire/journey.rb', line 2

def start_time
  @start_time
end

Instance Method Details

#durationObject



12
13
14
# File 'lib/cycle_hire/journey.rb', line 12

def duration
  ((@end_time - @start_time) / 60).to_i
end

#to_hObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/cycle_hire/journey.rb', line 16

def to_h
  {
    :start_time => @start_time,
    :start_station => @start_station.to_s,
    :end_time => @end_time,
    :end_station => @end_station.to_s,
    :cost => @cost,
    :duration => duration
  }
end