Class: FriendlyShipping::Rate

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

Defined Under Namespace

Classes: NoAmountsGiven

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shipping_method:, amounts:, remote_service_id: nil, delivery_date: nil, warnings: [], errors: [], data: {}) ⇒ Rate



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/friendly_shipping/rate.rb', line 21

def initialize(
  shipping_method:,
  amounts:,
  remote_service_id: nil,
  delivery_date: nil,
  warnings: [],
  errors: [],
  data: {}
)
  @remote_service_id = remote_service_id
  @shipping_method = shipping_method
  @amounts = amounts
  @delivery_date = delivery_date
  @warnings = warnings
  @errors = errors
  @data = data
end

Instance Attribute Details

#amountsObject (readonly)

Returns the value of attribute amounts.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def amounts
  @amounts
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def data
  @data
end

#delivery_dateObject (readonly)

Returns the value of attribute delivery_date.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def delivery_date
  @delivery_date
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def errors
  @errors
end

#remote_service_idObject (readonly)

Returns the value of attribute remote_service_id.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def remote_service_id
  @remote_service_id
end

#shipping_methodObject (readonly)

Returns the value of attribute shipping_method.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def shipping_method
  @shipping_method
end

#warningsObject (readonly)

Returns the value of attribute warnings.



6
7
8
# File 'lib/friendly_shipping/rate.rb', line 6

def warnings
  @warnings
end

Instance Method Details

#total_amountObject

Raises:



39
40
41
42
43
# File 'lib/friendly_shipping/rate.rb', line 39

def total_amount
  raise NoAmountsGiven if amounts.empty?

  amounts.map { |_name, amount| amount }.sum
end