Class: ShipmentCourier
- Inherits:
-
Object
- Object
- ShipmentCourier
- Defined in:
- app/models/shipment_courier.rb
Overview
A simple ruby object to provide parsing and normalization of courier code
normalizes courier code
provides a url to a carrier logo/icon
Instance Attribute Summary collapse
-
#courier_code ⇒ Object
readonly
Returns the value of attribute courier_code.
Instance Method Summary collapse
Constructor Details
#initialize(courier_code) ⇒ ShipmentCourier
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/shipment_courier.rb', line 11 def initialize(courier_code) normalized_courier_code = courier_code.to_s.downcase # index (not start_with?) so ShipEngine LTL carrier classes like # 'ShipengineFedExFreight' normalize to the carrier, not the fallback. @courier_code = if normalized_courier_code == 'fdx' || normalized_courier_code.index('fedex') :fedex elsif normalized_courier_code.start_with?('ups') :ups elsif normalized_courier_code.start_with?('usps') :usps elsif normalized_courier_code.index('canada') && normalized_courier_code.index('post') :canada_post elsif normalized_courier_code.index('speedee') || normalized_courier_code.index('spee dee') :speedee elsif normalized_courier_code.index('rlcarriers') || normalized_courier_code.index('r and l') :rlcarriers elsif normalized_courier_code.index('roadrunner') :roadrunner elsif normalized_courier_code.index('xpo') :xpo elsif normalized_courier_code.index('saia') :saia elsif normalized_courier_code.index('yrc') :yrc elsif normalized_courier_code.index('purolator') :purolator elsif normalized_courier_code.start_with?('canpar') :canpar else courier_code.to_s.downcase.parameterize.underscore.to_sym end end |
Instance Attribute Details
#courier_code ⇒ Object (readonly)
Returns the value of attribute courier_code.
7 8 9 |
# File 'app/models/shipment_courier.rb', line 7 def courier_code @courier_code end |
Instance Method Details
#courier_icon_url ⇒ String?
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/shipment_courier.rb', line 45 def courier_icon_url base_path = '//cdn2.warmlyyours.com/images/carriers/' case courier_code when :fedex "#{base_path}fedex.png" when :ups, :ups_freight "#{base_path}ups.png" when :purolator "#{base_path}purolator.png" when :canada_post "#{base_path}canadapost.png" end end |