Class: Edi::Houzz::ShipCodeMapper

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/houzz/ship_code_mapper.rb

Overview

Service object: ship code mapper.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orchestrator) ⇒ ShipCodeMapper

Returns a new instance of ShipCodeMapper.



13
14
15
16
17
18
19
20
21
22
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 13

def initialize(orchestrator)
  @orchestrator = orchestrator
  @shipping_map = [
    # These are Houzz codes, as best as can be determined by their documentation and our existing order history:
    ShippingOptionResult.new(code: 'Standard', name: 'fedex_ground'),
    ShippingOptionResult.new(code: 'Expedited', name: 'fedex_twoday'),
    ShippingOptionResult.new(code: 'ExpressSaver', name: 'fedex_express_saver'),
    ShippingOptionResult.new(code: 'StandardOvernight', name: 'fedex_standard_overnight')
  ]
end

Instance Attribute Details

#orchestratorObject (readonly)

Returns the value of attribute orchestrator.



11
12
13
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 11

def orchestrator
  @orchestrator
end

#shipping_mapObject (readonly)

Returns the value of attribute shipping_map.



11
12
13
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 11

def shipping_map
  @shipping_map
end

Instance Method Details

#hw_to_hz(shipping_method_name, signature: false, saturday: false) ⇒ Object

Translates a heatwave shipping option parameters into a houzz shipping code



34
35
36
37
38
39
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 34

def hw_to_hz(shipping_method_name, signature: false, saturday: false)
  match = shipping_map.find { |sor| sor.name == shipping_method_name && sor.signature == signature.to_b && sor.saturday == saturday.to_b }&.code
  raise "Unmatched shipping code #{shipping_method_name}" unless match

  match
end

#hz_to_hw(shipping_code, _carrier_code = nil, _is_puerto_rico = nil) ⇒ Object

Pass a Houzz shipping code and potentially a carrier code, and retrieves a shipping option result object describing the service requested



25
26
27
28
29
30
31
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 25

def hz_to_hw(shipping_code, _carrier_code = nil, _is_puerto_rico = nil)
  match = nil
  match ||= shipping_map.find { |sor| sor.code == shipping_code }
  raise "Unmatched shipping code #{shipping_code}" unless match

  match
end