Class: FriendlyShipping::Carrier

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

Overview

Represents a carrier (UPS, FedEx, etc.) and its ShippingMethod objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, name: nil, code: nil, shipping_methods: [], balance: nil, data: {}) ⇒ Carrier

Returns a new instance of Carrier.

Parameters:

  • id (Integer, String) (defaults to: nil)

    a unique identifier for this carrier

  • name (String) (defaults to: nil)

    the carrier's name

  • code (String) (defaults to: nil)

    the carrier's unique code

  • shipping_methods (Array<ShippingMethod>) (defaults to: [])

    the shipping methods available on this carrier

  • balance (Float) (defaults to: nil)

    the remaining balance for this carrier

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

    additional data related to this carrier



30
31
32
33
34
35
36
37
# File 'lib/friendly_shipping/carrier.rb', line 30

def initialize(id: nil, name: nil, code: nil, shipping_methods: [], balance: nil, data: {})
  @id = id
  @name = name
  @code = code
  @shipping_methods = shipping_methods
  @balance = balance
  @data = data
end

Instance Attribute Details

#balanceFloat (readonly)

Returns the remaining balance for this carrier.

Returns:

  • (Float)

    the remaining balance for this carrier



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

def balance
  @balance
end

#codeString (readonly)

Returns the carrier's unique code.

Returns:

  • (String)

    the carrier's unique code



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

def code
  @code
end

#dataHash (readonly)

Returns additional data related to this carrier.

Returns:

  • (Hash)

    additional data related to this carrier



22
23
24
# File 'lib/friendly_shipping/carrier.rb', line 22

def data
  @data
end

#idString (readonly)

Returns a unique identifier for this carrier.

Returns:

  • (String)

    a unique identifier for this carrier



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

def id
  @id
end

#nameString (readonly)

Returns the carrier's name.

Returns:

  • (String)

    the carrier's name



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

def name
  @name
end

#shipping_methodsArray<ShippingMethod> (readonly)

Returns the shipping methods available on this carrier.

Returns:

  • (Array<ShippingMethod>)

    the shipping methods available on this carrier



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

def shipping_methods
  @shipping_methods
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if the given object shares the same ID with this carrier.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


42
43
44
# File 'lib/friendly_shipping/carrier.rb', line 42

def ==(other)
  id == other.id
end