Class: Vehicle

Inherits:
CUMTD show all
Defined in:
lib/vehicle.rb

Instance Method Summary collapse

Methods inherited from CUMTD

all_routes, all_stops, #api_key, #get_departures_by_stop, #get_reroutes, #get_routes, #get_routes_by_stop, #get_shape_between_stops, #get_shape_by_id, #get_stop_by_id, #get_stop_times_by_stop, #get_stop_times_by_trip, #get_stops, #get_stops_by_lat_lon, #get_stops_by_search, #get_trip_by_id, #get_trips_by_block, #get_vehicle_by_id, #get_vehicles, #get_vehicles_by_route_id, #nearest_departures, #print_all_departures, reroutes, #serialize_routes, #serialize_stops, #serialize_vehicles

Constructor Details

#initialize(json) ⇒ Vehicle

Returns a new instance of Vehicle.



3
4
5
6
7
8
9
10
11
12
# File 'lib/vehicle.rb', line 3

def initialize(json)
	@vehicle_id = json["vehicle_id"]
	@trip = Trip.new(json["trip"])
	@location = Hash[:lat, json["location"]["lat"], :lon, json["location"]["lon"]]
	@previous_stop_id = json["previous_stop_id"]
	@next_stop_id = json["next_stop_id"]
	@origin_stop_id = json["origin_stop_id"]
	@destination_stop_id = json["destination_stop_id"]
	@last_updated = DateTime.parse(json["last_updated"]).to_time
end

Instance Method Details

#destination_stop_idObject



38
39
40
# File 'lib/vehicle.rb', line 38

def destination_stop_id
	@destination_stop_id
end

#last_updatedObject



42
43
44
# File 'lib/vehicle.rb', line 42

def last_updated
	@last_updated
end

#locationObject



22
23
24
# File 'lib/vehicle.rb', line 22

def location
	@location
end

#next_stop_idObject



30
31
32
# File 'lib/vehicle.rb', line 30

def next_stop_id
	@next_stop_id
end

#origin_stop_idObject



34
35
36
# File 'lib/vehicle.rb', line 34

def origin_stop_id
	@origin_stop_id
end

#previous_stop_idObject



26
27
28
# File 'lib/vehicle.rb', line 26

def previous_stop_id
	@previous_stop_id
end

#routeObject



46
47
48
# File 'lib/vehicle.rb', line 46

def route
	@@all_routes.select { |route| route.route_id == self.trip.route_id }
end

#to_json(*a) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/vehicle.rb', line 50

def to_json(*a)
	{
	'vehicle_id' => @vehicle_id,
	'lat' => @location[:lat],
	'lon' => @location[:lon],
	'trip' => @trip,
	'route' => self.route,
	}.to_json(*a)
end

#tripObject



18
19
20
# File 'lib/vehicle.rb', line 18

def trip
	@trip
end

#vehicle_idObject



14
15
16
# File 'lib/vehicle.rb', line 14

def vehicle_id
	@vehicle_id
end