Class: HotelBeds::Builder::HotelOccupancy
- Inherits:
-
Object
- Object
- HotelBeds::Builder::HotelOccupancy
- Defined in:
- lib/hotel_beds/builder/hotel_occupancy.rb
Instance Attribute Summary collapse
-
#rooms ⇒ Object
readonly
Returns the value of attribute rooms.
Instance Method Summary collapse
- #adult_count ⇒ Object
- #child_ages ⇒ Object
- #child_count ⇒ Object
-
#initialize(rooms) ⇒ HotelOccupancy
constructor
A new instance of HotelOccupancy.
- #to_h ⇒ Object
Constructor Details
#initialize(rooms) ⇒ HotelOccupancy
Returns a new instance of HotelOccupancy.
11 12 13 14 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 11 def initialize(rooms) self.rooms = rooms freeze end |
Instance Attribute Details
#rooms ⇒ Object
Returns the value of attribute rooms.
8 9 10 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 8 def rooms @rooms end |
Instance Method Details
#adult_count ⇒ Object
20 21 22 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 20 def adult_count rooms.map(&:adult_count).sum end |
#child_ages ⇒ Object
16 17 18 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 16 def child_ages rooms.map(&:child_ages).flatten_children end |
#child_count ⇒ Object
24 25 26 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 24 def child_count rooms.map(&:child_count).sum end |
#to_h ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 28 def to_h { RoomCount: rooms.size, Occupancy: { AdultCount: adult_count, ChildCount: child_count, GuestList: { Customer: 1.upto(adult_count).map { { :@type => "AD" } } + 1.upto(child_count).map { |i| { :@type => "CH", :Age => Integer(child_ages.fetch(i - 1)) } } } } } end |