Class: ReactiveShipping::RateEstimate
- Inherits:
-
Object
- Object
- ReactiveShipping::RateEstimate
- Defined in:
- lib/reactive_freight/rate_estimate.rb
Instance Attribute Summary collapse
-
#carrier ⇒ Object
Returns the value of attribute carrier.
-
#charge_items ⇒ Object
Returns the value of attribute charge_items.
-
#compare_price ⇒ Object
readonly
Returns the value of attribute compare_price.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#delivery_category ⇒ Object
Returns the value of attribute delivery_category.
-
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
-
#delivery_range ⇒ Object
readonly
Returns the value of attribute delivery_range.
-
#description ⇒ Object
Returns the value of attribute description.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#estimate_reference ⇒ Object
Returns the value of attribute estimate_reference.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#insurance_price ⇒ Object
readonly
Returns the value of attribute insurance_price.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#negotiated_rate ⇒ Object
readonly
Returns the value of attribute negotiated_rate.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#package_rates ⇒ Object
Returns the value of attribute package_rates.
-
#phone_required ⇒ Object
readonly
Returns the value of attribute phone_required.
-
#pickup_time ⇒ Object
Returns the value of attribute pickup_time.
-
#service_code ⇒ Object
Returns the value of attribute service_code.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#shipment_options ⇒ Object
Returns the value of attribute shipment_options.
-
#shipping_date ⇒ Object
readonly
Returns the value of attribute shipping_date.
-
#transit_days ⇒ Object
Returns the value of attribute transit_days.
-
#with_excessive_length_fees ⇒ Object
Returns the value of attribute with_excessive_length_fees.
Instance Method Summary collapse
- #add(package, rate = nil) ⇒ Object
-
#initialize(origin, destination, carrier, service_name, options = {}) ⇒ RateEstimate
constructor
A new instance of RateEstimate.
- #package_count ⇒ Object
- #packages ⇒ Object
- #total_price ⇒ Object (also: #price)
Constructor Details
#initialize(origin, destination, carrier, service_name, options = {}) ⇒ RateEstimate
Returns a new instance of RateEstimate.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reactive_freight/rate_estimate.rb', line 13 def initialize(origin, destination, carrier, service_name, = {}) self.charge_items = [:charge_items] || [] self.compare_price = [:compare_price] self.currency = [:currency] self.delivery_category = [:delivery_category] self.delivery_range = [:delivery_range] self.description = [:description] self.estimate_reference = [:estimate_reference] self.expires_at = [:expires_at] self.insurance_price = [:insurance_price] self. = [:messages] || [] self.negotiated_rate = [:negotiated_rate] self.origin = origin self.destination = destination self.carrier = carrier self.service_name = service_name self.package_rates = if [:package_rates] [:package_rates].map { |p| p.update(rate: Package.cents_from(p[:rate])) } else Array([:packages]).map { |p| { package: p } } end self.phone_required = [:phone_required] self.pickup_time = [:pickup_time] self.service_code = [:service_code] self. = [:shipment_options] || [] self.shipping_date = [:shipping_date] self.transit_days = [:transit_days] self.total_price = [:total_price] self.with_excessive_length_fees = .dig(:with_excessive_length_fees) self.delivery_date = @delivery_range.last end |
Instance Attribute Details
#carrier ⇒ Object
Returns the value of attribute carrier.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def carrier @carrier end |
#charge_items ⇒ Object
Returns the value of attribute charge_items.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def charge_items @charge_items end |
#compare_price ⇒ Object
Returns the value of attribute compare_price.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def compare_price @compare_price end |
#currency ⇒ Object
Returns the value of attribute currency.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def currency @currency end |
#delivery_category ⇒ Object
Returns the value of attribute delivery_category.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def delivery_category @delivery_category end |
#delivery_date ⇒ Object
Returns the value of attribute delivery_date.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def delivery_date @delivery_date end |
#delivery_range ⇒ Object
Returns the value of attribute delivery_range.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def delivery_range @delivery_range end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def description @description end |
#destination ⇒ Object
Returns the value of attribute destination.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def destination @destination end |
#estimate_reference ⇒ Object
Returns the value of attribute estimate_reference.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def estimate_reference @estimate_reference end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def expires_at @expires_at end |
#insurance_price ⇒ Object
Returns the value of attribute insurance_price.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def insurance_price @insurance_price end |
#messages ⇒ Object
Returns the value of attribute messages.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def @messages end |
#negotiated_rate ⇒ Object
Returns the value of attribute negotiated_rate.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def negotiated_rate @negotiated_rate end |
#origin ⇒ Object
Returns the value of attribute origin.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def origin @origin end |
#package_rates ⇒ Object
Returns the value of attribute package_rates.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def package_rates @package_rates end |
#phone_required ⇒ Object
Returns the value of attribute phone_required.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def phone_required @phone_required end |
#pickup_time ⇒ Object
Returns the value of attribute pickup_time.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def pickup_time @pickup_time end |
#service_code ⇒ Object
Returns the value of attribute service_code.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def service_code @service_code end |
#service_name ⇒ Object
Returns the value of attribute service_name.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def service_name @service_name end |
#shipment_options ⇒ Object
Returns the value of attribute shipment_options.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def @shipment_options end |
#shipping_date ⇒ Object
Returns the value of attribute shipping_date.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def shipping_date @shipping_date end |
#transit_days ⇒ Object
Returns the value of attribute transit_days.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def transit_days @transit_days end |
#with_excessive_length_fees ⇒ Object
Returns the value of attribute with_excessive_length_fees.
5 6 7 |
# File 'lib/reactive_freight/rate_estimate.rb', line 5 def with_excessive_length_fees @with_excessive_length_fees end |
Instance Method Details
#add(package, rate = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/reactive_freight/rate_estimate.rb', line 53 def add(package, rate = nil) cents = Package.cents_from(rate) if cents.nil? && total_price.nil? raise ArgumentError, 'New packages must have valid rate information since this RateEstimate has no total_price set.' end @package_rates << { package: package, rate: cents } self end |
#package_count ⇒ Object
67 68 69 |
# File 'lib/reactive_freight/rate_estimate.rb', line 67 def package_count package_rates.length end |
#packages ⇒ Object
63 64 65 |
# File 'lib/reactive_freight/rate_estimate.rb', line 63 def packages package_rates.map { |p| p[:package] } end |
#total_price ⇒ Object Also known as: price
46 47 48 49 50 |
# File 'lib/reactive_freight/rate_estimate.rb', line 46 def total_price @total_price || @package_rates.sum { |pr| pr[:rate] } rescue NoMethodError raise ArgumentError, 'RateEstimate must have a total_price set, or have a full set of valid package rates.' end |