Class: Parsec::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/parsec/order.rb

Constant Summary collapse

RES_STATUS =
{
  'OK' => 'Success', # 'New booking'
  'CA' => 'Cancelled',
  'OR' => 'On Request'
}.freeze

Constants inherited from Base

Base::DATE_FORMAT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_item_id:, rooms:, price:, hotel_code:, start_date:, end_date:, parsec_id:, status:) ⇒ Order

rubocop:disable Metrics/ParameterLists



14
15
16
17
18
19
20
21
22
23
# File 'lib/parsec/order.rb', line 14

def initialize(product_item_id:, rooms:, price:, hotel_code:, start_date:, end_date:, parsec_id:, status:)
  @product_item_id = product_item_id
  @rooms = rooms
  @price = price
  @hotel_code = hotel_code
  @start_date = start_date
  @end_date = end_date
  @parsec_id = parsec_id
  @status = status
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



11
12
13
# File 'lib/parsec/order.rb', line 11

def end_date
  @end_date
end

#hotel_codeObject (readonly)

Returns the value of attribute hotel_code.



11
12
13
# File 'lib/parsec/order.rb', line 11

def hotel_code
  @hotel_code
end

#numberObject (readonly)

Returns the value of attribute number.



11
12
13
# File 'lib/parsec/order.rb', line 11

def number
  @number
end

#parsec_idObject (readonly)

Returns the value of attribute parsec_id.



11
12
13
# File 'lib/parsec/order.rb', line 11

def parsec_id
  @parsec_id
end

#priceObject (readonly)

Returns the value of attribute price.



11
12
13
# File 'lib/parsec/order.rb', line 11

def price
  @price
end

#roomsObject (readonly)

Returns the value of attribute rooms.



11
12
13
# File 'lib/parsec/order.rb', line 11

def rooms
  @rooms
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



11
12
13
# File 'lib/parsec/order.rb', line 11

def start_date
  @start_date
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/parsec/order.rb', line 11

def status
  @status
end

Class Method Details

.build(order_data) ⇒ Object

rubocop:disable Metrics/AbcSize



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/parsec/order.rb', line 27

def self.build(order_data)
  hotel_data = order_data[:hotel_res_list][:hotel_res]
  new(product_item_id: order_data[:res_global_info][:res_i_ds][:res_id].find { |id| id[:@type] == 'ClientReference' }[:@id],
      rooms: Array.wrap(hotel_data[:rooms][:room]).map { |r| [r[:room_type][:@code], r[:room_type][:@name]] }.to_h,
      hotel_code: hotel_data[:info][:@hotel_code],
      start_date: Date.strptime(hotel_data[:hotel_res_info][:date_range][:@start], DATE_FORMAT),
      end_date: Date.strptime(hotel_data[:hotel_res_info][:date_range][:@end], DATE_FORMAT),
      price: hotel_data[:hotel_res_info][:total][:@amount].to_f,
      parsec_id: hotel_data[:hotel_res_info][:hotel_res_i_ds][:hotel_res_id].find { |id| id[:@type] == 'Locator' }[:@id],
      status: RES_STATUS[hotel_data[:@res_status]])
end