Class: Asdawqw::RatesAvailability

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/asdawqw/models/rates_availability.rb

Overview

Rates Availability model

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(product_id = nil, lead_time = nil, rates = nil, min_stays = nil, max_stays = nil, restrictions = nil, availabilities = nil, available_count = nil) ⇒ RatesAvailability

Returns a new instance of RatesAvailability.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/asdawqw/models/rates_availability.rb', line 57

def initialize(product_id = nil,
               lead_time = nil,
               rates = nil,
               min_stays = nil,
               max_stays = nil,
               restrictions = nil,
               availabilities = nil,
               available_count = nil)
  @product_id = product_id
  @lead_time = lead_time
  @rates = rates
  @min_stays = min_stays
  @max_stays = max_stays
  @restrictions = restrictions
  @availabilities = availabilities
  @available_count = available_count
end

Instance Attribute Details

#availabilitiesList of AvailabilityModel

List of models

Returns:



37
38
39
# File 'lib/asdawqw/models/rates_availability.rb', line 37

def availabilities
  @availabilities
end

#available_countList of AvailableCount

List of models (Only for MLT properties)

Returns:



41
42
43
# File 'lib/asdawqw/models/rates_availability.rb', line 41

def available_count
  @available_count
end

#lead_timeInteger

Number of days before reservation in which reservation couldn’t be made. Allowed values are 0-7. If this value is set on property level - it will be used before than value on PM level.

Returns:

  • (Integer)


17
18
19
# File 'lib/asdawqw/models/rates_availability.rb', line 17

def lead_time
  @lead_time
end

#max_staysList of MaxStayModel

List of models

Returns:



29
30
31
# File 'lib/asdawqw/models/rates_availability.rb', line 29

def max_stays
  @max_stays
end

#min_staysList of MinStayModel

List of models

Returns:



25
26
27
# File 'lib/asdawqw/models/rates_availability.rb', line 25

def min_stays
  @min_stays
end

#product_idInteger

ID of the product

Returns:

  • (Integer)


11
12
13
# File 'lib/asdawqw/models/rates_availability.rb', line 11

def product_id
  @product_id
end

#ratesList of Rate

List of models

Returns:



21
22
23
# File 'lib/asdawqw/models/rates_availability.rb', line 21

def rates
  @rates
end

#restrictionsList of Restriction

List of models

Returns:



33
34
35
# File 'lib/asdawqw/models/rates_availability.rb', line 33

def restrictions
  @restrictions
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/asdawqw/models/rates_availability.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  product_id = hash['productId']
  lead_time = hash['leadTime']
  # Parameter is an array, so we need to iterate through it
  rates = nil
  unless hash['rates'].nil?
    rates = []
    hash['rates'].each do |structure|
      rates << (Rate.from_hash(structure) if structure)
    end
  end
  # Parameter is an array, so we need to iterate through it
  min_stays = nil
  unless hash['minStays'].nil?
    min_stays = []
    hash['minStays'].each do |structure|
      min_stays << (MinStayModel.from_hash(structure) if structure)
    end
  end
  # Parameter is an array, so we need to iterate through it
  max_stays = nil
  unless hash['maxStays'].nil?
    max_stays = []
    hash['maxStays'].each do |structure|
      max_stays << (MaxStayModel.from_hash(structure) if structure)
    end
  end
  # Parameter is an array, so we need to iterate through it
  restrictions = nil
  unless hash['restrictions'].nil?
    restrictions = []
    hash['restrictions'].each do |structure|
      restrictions << (Restriction.from_hash(structure) if structure)
    end
  end
  # Parameter is an array, so we need to iterate through it
  availabilities = nil
  unless hash['availabilities'].nil?
    availabilities = []
    hash['availabilities'].each do |structure|
      availabilities << (AvailabilityModel.from_hash(structure) if structure)
    end
  end
  # Parameter is an array, so we need to iterate through it
  available_count = nil
  unless hash['availableCount'].nil?
    available_count = []
    hash['availableCount'].each do |structure|
      available_count << (AvailableCount.from_hash(structure) if structure)
    end
  end

  # Create object from extracted values.
  RatesAvailability.new(product_id,
                        lead_time,
                        rates,
                        min_stays,
                        max_stays,
                        restrictions,
                        availabilities,
                        available_count)
end

.namesObject

A mapping from model property names to API property names.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/asdawqw/models/rates_availability.rb', line 44

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['product_id'] = 'productId'
  @_hash['lead_time'] = 'leadTime'
  @_hash['rates'] = 'rates'
  @_hash['min_stays'] = 'minStays'
  @_hash['max_stays'] = 'maxStays'
  @_hash['restrictions'] = 'restrictions'
  @_hash['availabilities'] = 'availabilities'
  @_hash['available_count'] = 'availableCount'
  @_hash
end