Class: CitibikeTrips::Trip

Inherits:
Object
  • Object
show all
Defined in:
lib/citibike_trips/trip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, start_station, end_station, start_timestamp, end_timestamp) ⇒ Trip

Returns a new instance of Trip.



6
7
8
9
10
11
12
13
# File 'lib/citibike_trips/trip.rb', line 6

def initialize(id, start_station, end_station, start_timestamp, end_timestamp)
  @id = id
  stations = CitibikeTrips::Stations.new
  @start_station = stations[start_station.to_i]
  @end_station = stations[end_station.to_i]
  @start_timestamp = Time.at(start_timestamp.to_i)
  @end_timestamp = Time.at(end_timestamp.to_i)
end

Instance Attribute Details

#end_stationObject (readonly)

Returns the value of attribute end_station.



4
5
6
# File 'lib/citibike_trips/trip.rb', line 4

def end_station
  @end_station
end

#end_timestampObject (readonly)

Returns the value of attribute end_timestamp.



4
5
6
# File 'lib/citibike_trips/trip.rb', line 4

def end_timestamp
  @end_timestamp
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/citibike_trips/trip.rb', line 4

def id
  @id
end

#start_stationObject (readonly)

Returns the value of attribute start_station.



4
5
6
# File 'lib/citibike_trips/trip.rb', line 4

def start_station
  @start_station
end

#start_timestampObject (readonly)

Returns the value of attribute start_timestamp.



4
5
6
# File 'lib/citibike_trips/trip.rb', line 4

def start_timestamp
  @start_timestamp
end

Instance Method Details

#to_json(*a) ⇒ Object



15
16
17
# File 'lib/citibike_trips/trip.rb', line 15

def to_json(*a)
  Hash[instance_variables.collect{|i| [i[1..-1], instance_variable_get(i)]}].to_json(*a)
end