Class: Workarea::ShippingOption
- Inherits:
-
Object
- Object
- Workarea::ShippingOption
- Includes:
- GuardNegativePrice
- Defined in:
- app/models/workarea/shipping_option.rb
Instance Attribute Summary collapse
-
#carrier ⇒ Object
readonly
Returns the value of attribute carrier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #price_adjustments ⇒ Object
-
#service_code ⇒ Object
readonly
Returns the value of attribute service_code.
-
#tax_code ⇒ Object
readonly
Returns the value of attribute tax_code.
Class Method Summary collapse
Instance Method Summary collapse
- #base_price ⇒ Object
-
#initialize(attributes = {}) ⇒ ShippingOption
constructor
A new instance of ShippingOption.
- #price ⇒ Object
- #to_h ⇒ Object
Methods included from GuardNegativePrice
Constructor Details
#initialize(attributes = {}) ⇒ ShippingOption
Returns a new instance of ShippingOption.
21 22 23 24 25 26 |
# File 'app/models/workarea/shipping_option.rb', line 21 def initialize(attributes = {}) @attributes = attributes.with_indifferent_access attributes.each do |name, value| instance_variable_set("@#{name}", value) end end |
Instance Attribute Details
#carrier ⇒ Object (readonly)
Returns the value of attribute carrier.
5 6 7 |
# File 'app/models/workarea/shipping_option.rb', line 5 def carrier @carrier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'app/models/workarea/shipping_option.rb', line 5 def name @name end |
#price_adjustments ⇒ Object
32 33 34 |
# File 'app/models/workarea/shipping_option.rb', line 32 def price_adjustments @price_adjustments || [] end |
#service_code ⇒ Object (readonly)
Returns the value of attribute service_code.
5 6 7 |
# File 'app/models/workarea/shipping_option.rb', line 5 def service_code @service_code end |
#tax_code ⇒ Object (readonly)
Returns the value of attribute tax_code.
5 6 7 |
# File 'app/models/workarea/shipping_option.rb', line 5 def tax_code @tax_code end |
Class Method Details
.from_rate_estimate(rate) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/workarea/shipping_option.rb', line 8 def self.from_rate_estimate(rate) new( carrier: rate.carrier, name: rate.service_name, service_code: rate.service_code, price: Money.new(rate.price, rate.currency), tax_code: Shipping::Service.find_tax_code( rate.carrier, rate.service_name ) ) end |
Instance Method Details
#base_price ⇒ Object
28 29 30 |
# File 'app/models/workarea/shipping_option.rb', line 28 def base_price (@price || 0).to_m end |
#price ⇒ Object
36 37 38 39 40 |
# File 'app/models/workarea/shipping_option.rb', line 36 def price guard_negative_price do base_price + price_adjustments.map(&:amount).sum.to_m end end |
#to_h ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/workarea/shipping_option.rb', line 42 def to_h { carrier: carrier, name: name, service_code: service_code, price: price, base_price: base_price, tax_code: tax_code } end |