Class: FriendlyShipping::ShippingMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/shipping_method.rb

Overview

Represents a shipping method (UPS Ground, USPS Priority, etc.) that belongs to a Carrier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, service_code: nil, domestic: nil, international: nil, multi_package: nil, carrier: nil, origin_countries: [], data: {}) ⇒ ShippingMethod

Returns a new instance of ShippingMethod.

Parameters:

  • name (String) (defaults to: nil)

    the shipping method's name

  • service_code (String) (defaults to: nil)

    the shipping method's service code

  • domestic (Boolean) (defaults to: nil)

    whether this is a domestic shipping method

  • international (Boolean) (defaults to: nil)

    whether this is an international shipping method

  • multi_package (Boolean) (defaults to: nil)

    whether this is a multi-package shipping method

  • carrier (Carrier) (defaults to: nil)

    this shipping method's carrier

  • origin_countries (Array) (defaults to: [])

    countries this shipping method ships from

  • data (Hash) (defaults to: {})

    additional carrier-specific data for this shipping method



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/friendly_shipping/shipping_method.rb', line 29

def initialize(
  name: nil,
  service_code: nil,
  domestic: nil,
  international: nil,
  multi_package: nil,
  carrier: nil,
  origin_countries: [],
  data: {}
)
  @name = name
  @service_code = service_code
  @domestic = domestic
  @international = international
  @multi_package = multi_package
  @carrier = carrier
  @origin_countries = origin_countries
  @data = data
end

Instance Attribute Details

#carrierCarrier (readonly)

Returns this shipping method's carrier.

Returns:

  • (Carrier)

    this shipping method's carrier



13
14
15
# File 'lib/friendly_shipping/shipping_method.rb', line 13

def carrier
  @carrier
end

#dataHash (readonly)

Returns additional carrier-specific data for this shipping method.

Returns:

  • (Hash)

    additional carrier-specific data for this shipping method



19
20
21
# File 'lib/friendly_shipping/shipping_method.rb', line 19

def data
  @data
end

#nameString (readonly)

Returns the shipping method's name.

Returns:

  • (String)

    the shipping method's name



7
8
9
# File 'lib/friendly_shipping/shipping_method.rb', line 7

def name
  @name
end

#origin_countriesArray<String> (readonly)

Returns countries this shipping method ships from.

Returns:

  • (Array<String>)

    countries this shipping method ships from



16
17
18
# File 'lib/friendly_shipping/shipping_method.rb', line 16

def origin_countries
  @origin_countries
end

#service_codeString (readonly)

Returns the shipping method's service code.

Returns:

  • (String)

    the shipping method's service code



10
11
12
# File 'lib/friendly_shipping/shipping_method.rb', line 10

def service_code
  @service_code
end

Instance Method Details

#domestic?Boolean

Returns true if this is a domestic shipping method.

Returns:

  • (Boolean)


51
52
53
# File 'lib/friendly_shipping/shipping_method.rb', line 51

def domestic?
  !!domestic
end

#international?Boolean

Returns true if this is an international shipping method.

Returns:

  • (Boolean)


57
58
59
# File 'lib/friendly_shipping/shipping_method.rb', line 57

def international?
  !!international
end

#multi_package?Boolean

Returns true if this shipping method supports multiple packages.

Returns:

  • (Boolean)


63
64
65
# File 'lib/friendly_shipping/shipping_method.rb', line 63

def multi_package?
  !!multi_package
end