Class: Trip
Constant Summary
collapse
- WHITELISTED_ATTRS =
[:departure_date, :departure_place, :arrival_place, :price, :seats_left, :duration, :distance, :car, :links]
Class Method Summary
collapse
Instance Method Summary
collapse
#attributes, #attributes=
Constructor Details
#initialize(hash) ⇒ Trip
Returns a new instance of Trip.
12
13
14
|
# File 'lib/blabla_client/trip.rb', line 12
def initialize(hash)
self.attributes = hash.keep_if {|k,v| WHITELISTED_ATTRS.include?(k)}
end
|
Class Method Details
.parse_response(json_response) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/blabla_client/trip.rb', line 16
def self.parse_response(json_response)
response = {}
response_hash = JSON.parse json_response, :symbolize_names => true
unless response_hash[:trips].nil?
response[:trips] = response_hash[:trips].collect {|t| Trip.new(t)}
end
unless response_hash[:pager].nil?
response[:page] = response_hash[:pager][:page]
response[:pages] = response_hash[:pager][:pages]
response[:count] = response_hash[:pager][:total]
end
response
end
|
Instance Method Details
#get_arrival_place ⇒ Object
51
52
53
54
55
|
# File 'lib/blabla_client/trip.rb', line 51
def get_arrival_place
full_address = arrival_place[:address]
full_address += ", #{arrival_place[:city_name]}" unless arrival_place[:address].include?(arrival_place[:city_name])
full_address
end
|
#get_car ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/blabla_client/trip.rb', line 72
def get_car
car_hash = {}
unless car.nil? || car.empty?
car_hash[:model] = car[:make]
car_hash[:model] += " #{car[:model]}" unless car[:model].nil?
car_hash[:comfort] = car[:comfort_nb_star]
end
car_hash
end
|
#get_departure_date ⇒ Object
38
39
40
41
42
43
|
# File 'lib/blabla_client/trip.rb', line 38
def get_departure_date
departure_fields = departure_date.split(' ')
date_fields = departure_fields[0].split('/')
time_fields = departure_fields[1].split(':')
Time.new(date_fields[2].to_i, date_fields[1].to_i, date_fields[0].to_i, time_fields[0].to_i, time_fields[1].to_i, time_fields[2].to_i)
end
|
#get_departure_place ⇒ Object
45
46
47
48
49
|
# File 'lib/blabla_client/trip.rb', line 45
def get_departure_place
full_address = departure_place[:address]
full_address += ", #{departure_place[:city_name]}" unless departure_place[:address].include?(departure_place[:city_name])
full_address
end
|
#get_distance ⇒ Object
68
69
70
|
# File 'lib/blabla_client/trip.rb', line 68
def get_distance
distance[:value] unless distance.nil?
end
|
#get_duration ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/blabla_client/trip.rb', line 57
def get_duration
duration_hash = {}
unless duration.nil? || duration.empty?
if duration[:unity] == 's'
duration_hash[:hours] = (duration[:value].to_f/3600).floor
duration_hash[:minutes] = ((duration[:value] - duration_hash[:hours]*3600).to_f/60).floor
end
end
duration_hash
end
|
#get_price ⇒ Object
34
35
36
|
# File 'lib/blabla_client/trip.rb', line 34
def get_price
{:value => price[:value], :currency => price[:symbol], :color => price[:price_color].downcase}
end
|
#get_url ⇒ Object
30
31
32
|
# File 'lib/blabla_client/trip.rb', line 30
def get_url
links[:_front]
end
|