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
- #courier_icon_url ⇒ Object
-
#initialize(courier_code) ⇒ ShipmentCourier
constructor
A new instance of ShipmentCourier.
Constructor Details
#initialize(courier_code) ⇒ ShipmentCourier
Returns a new instance of ShipmentCourier.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/shipment_courier.rb', line 8 def initialize(courier_code) normalized_courier_code = courier_code.to_s.downcase if normalized_courier_code == 'fdx' || normalized_courier_code.start_with?('fedex') @courier_code = :fedex elsif normalized_courier_code.start_with?('ups') @courier_code = :ups elsif normalized_courier_code.start_with?('usps') @courier_code = :usps elsif normalized_courier_code.index('canada') && normalized_courier_code.index('post') @courier_code = :canada_post elsif normalized_courier_code.index('speedee') || normalized_courier_code.index('spee dee') @courier_code = :speedee elsif normalized_courier_code.index('rlcarriers') || normalized_courier_code.index('r and l') @courier_code = :rlcarriers elsif normalized_courier_code.index('yrc') @courier_code = :yrc elsif normalized_courier_code.index('purolator') @courier_code = :purolator elsif normalized_courier_code.start_with?('canpar') @courier_code = :canpar else @courier_code = 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.
6 7 8 |
# File 'app/models/shipment_courier.rb', line 6 def courier_code @courier_code end |
Instance Method Details
#courier_icon_url ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/shipment_courier.rb', line 33 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 |