Class: HotelBeds::Builder::HotelOccupancy

Inherits:
Object
  • Object
show all
Defined in:
lib/hotel_beds/builder/hotel_occupancy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#roomsObject

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_countObject



20
21
22
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 20

def adult_count
  rooms.map(&:adult_count).sum
end

#child_agesObject



16
17
18
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 16

def child_ages
  rooms.map(&:child_ages).flatten_children
end

#child_countObject



24
25
26
# File 'lib/hotel_beds/builder/hotel_occupancy.rb', line 24

def child_count
  rooms.map(&:child_count).sum
end

#to_hObject



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