class Omniship::RateEstimate
Attributes
carrier[R]
currency[R]
delivery_date[R]
delivery_range[R]
destination[R]
origin[R]
package_rates[R]
service_code[R]
service_name[R]
Public Class Methods
new(origin, destination, carrier, options={})
click to toggle source
# File lib/omniship/rate_estimate.rb, line 14 def initialize(origin, destination, carrier, options={}) @origin, @destination, @carrier = origin, destination, carrier @service_name = options[:service_name] @service_code = options[:service_code] if options[:package_rates] @package_rates = options[:package_rates].map {|p| p.update({:rate => Package.cents_from(p[:rate])}) } else @package_rates = Array(options[:packages]).map {|p| {:package => p}} end @total_price = options[:total_price] @currency = options[:currency] @delivery_range = options[:delivery_range] ? options[:delivery_range].map { |date| date_for(date) }.compact : [] @delivery_date = options[:delivery_date] end
Public Instance Methods
add(package,rate=nil)
click to toggle source
# File lib/omniship/rate_estimate.rb, line 38 def add(package,rate=nil) cents = Package.cents_from(rate) raise ArgumentError.new("New packages must have valid rate information since this RateEstimate has no total_price set.") if cents.nil? and total_price.nil? @package_rates << {:package => package, :rate => cents} self end
package_count()
click to toggle source
# File lib/omniship/rate_estimate.rb, line 49 def package_count package_rates.length end
packages()
click to toggle source
# File lib/omniship/rate_estimate.rb, line 45 def packages package_rates.map {|p| p[:package]} end
total_price()
click to toggle source
# File lib/omniship/rate_estimate.rb, line 29 def total_price begin @total_price || @package_rates.sum {|p| p[:rate]} rescue NoMethodError raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.") end end
Also aliased as: price
Private Instance Methods
date_for(date)
click to toggle source
# File lib/omniship/rate_estimate.rb, line 54 def date_for(date) date && DateTime.strptime(date.to_s, "%Y-%m-%d") rescue ArgumentError nil end