Class: ExpediaApi::Entities::SearchEntity

Inherits:
Object
  • Object
show all
Defined in:
lib/expedia_api/entities/search_entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ SearchEntity

Returns a new instance of SearchEntity.



6
7
8
# File 'lib/expedia_api/entities/search_entity.rb', line 6

def initialize(raw_data)
  @raw_data = raw_data || {}
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



4
5
6
# File 'lib/expedia_api/entities/search_entity.rb', line 4

def raw_data
  @raw_data
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/expedia_api/entities/search_entity.rb', line 10

def available?
  if raw_data[:Price]
    !!raw_data[:Price].fetch(:TotalRate, nil)
  else
    false
  end
end

#currencyObject



51
52
53
54
55
56
57
# File 'lib/expedia_api/entities/search_entity.rb', line 51

def currency
  if available?
    raw_data[:Price][:TotalRate][:Currency]
  else
    nil
  end
end

#expedia_idObject



63
64
65
# File 'lib/expedia_api/entities/search_entity.rb', line 63

def expedia_id
  id
end

#has_promotion?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/expedia_api/entities/search_entity.rb', line 67

def has_promotion?
  !!raw_data[:Promotion].fetch(:Amount, nil)
end

#hotel_mandatory_taxes_and_feesObject



35
36
37
38
39
40
41
# File 'lib/expedia_api/entities/search_entity.rb', line 35

def hotel_mandatory_taxes_and_fees
  if raw_data[:HotelMandatoryTaxesAndFees] && raw_data[:HotelMandatoryTaxesAndFees][:Value]
    raw_data[:HotelMandatoryTaxesAndFees][:Value].to_f
  else
    nil
  end
end

#hotel_mandatory_taxes_and_fees_currencyObject



43
44
45
46
47
48
49
# File 'lib/expedia_api/entities/search_entity.rb', line 43

def hotel_mandatory_taxes_and_fees_currency
  if raw_data[:HotelMandatoryTaxesAndFees] && raw_data[:HotelMandatoryTaxesAndFees][:Currency]
    raw_data[:HotelMandatoryTaxesAndFees][:Currency]
  else
    nil
  end
end

#idObject



59
60
61
# File 'lib/expedia_api/entities/search_entity.rb', line 59

def id
  raw_data[:HotelID].to_i
end

#promotion_currencyObject



87
88
89
90
91
92
93
# File 'lib/expedia_api/entities/search_entity.rb', line 87

def promotion_currency
  if has_promotion?
    raw_data[:Promotion][:Amount][:Currency]
  else
    nil
  end
end

#promotion_textObject



71
72
73
74
75
76
77
# File 'lib/expedia_api/entities/search_entity.rb', line 71

def promotion_text
  if has_promotion?
    raw_data[:Promotion][:Description]
  else
    nil
  end
end

#promotion_valueObject



79
80
81
82
83
84
85
# File 'lib/expedia_api/entities/search_entity.rb', line 79

def promotion_value
  if has_promotion?
    raw_data[:Promotion][:Amount][:Value].to_f
  else
    nil
  end
end

#sold_out?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/expedia_api/entities/search_entity.rb', line 18

def sold_out?
  !available?
end

#total_price_including_taxesObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/expedia_api/entities/search_entity.rb', line 22

def total_price_including_taxes
  if available?
    price = raw_data[:Price][:TotalRate][:Value].to_f
    if hotel_mandatory_taxes_and_fees
      price + hotel_mandatory_taxes_and_fees
    else
      price
    end
  else
    nil
  end
end