Class: QuickTravel::Reservation
- Inherits:
-
Adapter
- Object
- Adapter
- QuickTravel::Reservation
show all
- Defined in:
- lib/quick_travel/reservation.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Adapter
all, belongs_to, find, has_many, #to_s, update
#define_readers, #initialize, #to_hash
Class Method Details
.create(options) ⇒ Object
12
13
14
15
|
# File 'lib/quick_travel/reservation.rb', line 12
def self.create(options)
json = post_and_validate('/api/reservations.json', options, expect: :json)
new(json)
end
|
.destroy(id) ⇒ Object
17
18
19
|
# File 'lib/quick_travel/reservation.rb', line 17
def self.destroy(id)
delete_and_validate("/api/reservations/#{id}.json")
end
|
Instance Method Details
#adjusted? ⇒ Boolean
67
68
69
|
# File 'lib/quick_travel/reservation.rb', line 67
def adjusted?
pre_adjusted_gross_including_packaged_item != gross_including_packaged_item
end
|
#end_date_time ⇒ Object
29
30
31
|
# File 'lib/quick_travel/reservation.rb', line 29
def end_date_time
end_time.to_time.on(last_travel_date) if end_time
end
|
#passenger_splits ⇒ Object
33
34
35
|
# File 'lib/quick_travel/reservation.rb', line 33
def passenger_splits
@_passenger_splits ||= @passenger_splits.map{ |split| PassengerSplit.new(split) }
end
|
#passengers_count(booking) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/quick_travel/reservation.rb', line 41
def passengers_count(booking)
passenger_type_count = {}
if passenger_splits.present?
passenger_splits.each do |p|
passenger = booking.find_passenger_by_id(p.consumer_id)
if passenger.present?
passenger_type_count[passenger.passenger_type_id] ||= 0
passenger_type_count[passenger.passenger_type_id] += 1
end
end
end
PassengerType.passenger_counts(passenger_type_count)
end
|
#passengers_count_string(booking) ⇒ Object
37
38
39
|
# File 'lib/quick_travel/reservation.rb', line 37
def passengers_count_string(booking)
passengers_count(booking).join(', ')
end
|
#resource ⇒ Object
21
22
23
|
# File 'lib/quick_travel/reservation.rb', line 21
def resource
@resource ||= QuickTravel::Resource.find(resource_id) if resource_id
end
|
#start_date_time ⇒ Object
25
26
27
|
# File 'lib/quick_travel/reservation.rb', line 25
def start_date_time
start_time.to_time.on(first_travel_date) if start_time
end
|
#vehicle_count_string(booking) ⇒ Object
56
57
58
|
# File 'lib/quick_travel/reservation.rb', line 56
def vehicle_count_string(booking)
vehicles_count(booking).to_sentence
end
|
#vehicles_count(booking) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/quick_travel/reservation.rb', line 60
def vehicles_count(booking)
vehicle_splits.map do|v|
vehicle = booking.find_vehicle_by_id(v['consumer_id'])
"#{vehicle.length}m #{vehicle.vehicle_type.name}"
end
end
|