Class: Edi::Houzz::ShipCodeMapper
- Inherits:
-
Object
- Object
- Edi::Houzz::ShipCodeMapper
- Defined in:
- app/services/edi/houzz/ship_code_mapper.rb
Instance Attribute Summary collapse
-
#orchestrator ⇒ Object
readonly
Returns the value of attribute orchestrator.
-
#shipping_map ⇒ Object
readonly
Returns the value of attribute shipping_map.
Instance Method Summary collapse
-
#hw_to_hz(shipping_method_name, signature: false, saturday: false) ⇒ Object
Translates a heatwave shipping option parameters into a houzz shipping code.
-
#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.
-
#initialize(orchestrator) ⇒ ShipCodeMapper
constructor
A new instance of ShipCodeMapper.
Constructor Details
#initialize(orchestrator) ⇒ ShipCodeMapper
Returns a new instance of ShipCodeMapper.
12 13 14 15 16 17 18 19 20 21 |
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 12 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
#orchestrator ⇒ Object (readonly)
Returns the value of attribute orchestrator.
10 11 12 |
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 10 def orchestrator @orchestrator end |
#shipping_map ⇒ Object (readonly)
Returns the value of attribute shipping_map.
10 11 12 |
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 10 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
32 33 34 35 36 |
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 32 def hw_to_hz(shipping_method_name, signature: false, saturday: false) match = shipping_map.detect { |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
24 25 26 27 28 29 |
# File 'app/services/edi/houzz/ship_code_mapper.rb', line 24 def hz_to_hw(shipping_code, carrier_code = nil, is_puerto_rico = nil) match = nil match ||= shipping_map.detect { |sor| sor.code == shipping_code } raise "Unmatched shipping code #{shipping_code}" unless match match end |