Class: ShipmentCourier

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
  @courier_code = if normalized_courier_code == 'fdx' || normalized_courier_code.start_with?('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('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_codeObject (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_urlObject



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