Class: Bodega::ShippingMethod::Base

Inherits:
Object
  • Object
show all
Extended by:
Optional
Includes:
ActiveMerchant::Shipping
Defined in:
lib/bodega/shipping_method/base.rb

Direct Known Subclasses

UPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Optional

options

Constructor Details

#initialize(order) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/bodega/shipping_method/base.rb', line 11

def initialize(order)
  self.order = order
end

Instance Attribute Details

#orderObject

Returns the value of attribute order.



9
10
11
# File 'lib/bodega/shipping_method/base.rb', line 9

def order
  @order
end

Instance Method Details

#ratesObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bodega/shipping_method/base.rb', line 15

def rates
  return {} unless packages.any?
  @rates ||= {}.tap do |rates|
    response = client.find_rates(origin, destination, packages)
    response.rates.sort_by(&:price).each do |rate|
      rates[rate.service_code] = {
        name: rate.service_name,
        price: rate.price
      }
    end
  end
end