Class: FriendlyShipping::Rate
- Inherits:
-
Object
- Object
- FriendlyShipping::Rate
- Defined in:
- lib/friendly_shipping/rate.rb
Defined Under Namespace
Classes: NoAmountsGiven
Instance Attribute Summary collapse
-
#amounts ⇒ Object
readonly
Returns the value of attribute amounts.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#delivery_date ⇒ Object
readonly
Returns the value of attribute delivery_date.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#remote_service_id ⇒ Object
readonly
Returns the value of attribute remote_service_id.
-
#shipping_method ⇒ Object
readonly
Returns the value of attribute shipping_method.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(shipping_method:, amounts:, remote_service_id: nil, delivery_date: nil, warnings: [], errors: [], data: {}) ⇒ Rate
constructor
A new instance of Rate.
- #total_amount ⇒ Object
Constructor Details
#initialize(shipping_method:, amounts:, remote_service_id: nil, delivery_date: nil, warnings: [], errors: [], data: {}) ⇒ Rate
Returns a new instance of 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
#amounts ⇒ Object (readonly)
Returns the value of attribute amounts.
6 7 8 |
# File 'lib/friendly_shipping/rate.rb', line 6 def amounts @amounts end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/friendly_shipping/rate.rb', line 6 def data @data end |
#delivery_date ⇒ Object (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 |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/friendly_shipping/rate.rb', line 6 def errors @errors end |
#remote_service_id ⇒ Object (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_method ⇒ Object (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 |
#warnings ⇒ Object (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_amount ⇒ Object
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(Money.new(0, 'USD')) end |