Class: ActiveShipping::RateEstimate

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shipping/rate_estimate.rb

Overview

Class representing a shipping option with estimated price.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, destination, carrier, service_name, options = {}) ⇒ RateEstimate

Returns a new instance of RateEstimate.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/active_shipping/rate_estimate.rb', line 91

def initialize(origin, destination, carrier, service_name, options = {})
  self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
  self.service_code = options[:service_code]
  self.description = options[:description]
  self.estimate_reference = options[:estimate_reference]
  self.pickup_time = options[:pickup_time]
  self.expires_at = options[:expires_at]
  if options[:package_rates]
    self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
  else
    self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
  end
  self.total_price = options[:total_price]
  self.negotiated_rate = options[:negotiated_rate]
  self.compare_price = options[:compare_price]
  self.phone_required = options[:phone_required]
  self.currency = options[:currency]
  self.delivery_range = options[:delivery_range]
  self.shipping_date = options[:shipping_date]
  self.delivery_date = @delivery_range.last
  self.insurance_price = options[:insurance_price]
  self.delivery_category = options[:delivery_category]
  self.shipment_options = options[:shipment_options] || []
  self.charge_items = options[:charge_items] || []
  self.messages = options[:messages] || []
end

Instance Attribute Details

#carrierString

The name of the carrier (e.g. 'USPS', 'FedEx')

Returns:

  • (String)

See Also:

  • Carrier.name


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#charge_itemsArray<{ group: String, code: String, name: String, description: String, amount: Integer }>

Breakdown of a shipping rate's price with amounts in cents.

Returns:

  • (Array<{ group: String, code: String, name: String, description: String, amount: Integer }>)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#compare_priceInteger

The comparable price in cents

Returns:

  • (Integer)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#currencyString

ISO4217 currency code of the quoted rate estimates (e.g. CAD, EUR, or USD)

Returns:

  • (String)

See Also:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#delivery_categoryString

The general classification of the delivery method

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#delivery_dateDate

The date on which the shipment will be delivered. This is usually only available for express shipments; in other cases a #delivery_range is given instead.

Returns:

  • (Date)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#delivery_rangeArray<Date>

The minimum and maximum date of when the shipment is expected to be delivered

Returns:

  • (Array<Date>)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#descriptionString

Public description of the shipping service (e.g. '2 days delivery')

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#destinationActiveShipping::Location

The destination of the shipment



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#estimate_referenceObject

Returns the value of attribute estimate_reference.



83
84
85
# File 'lib/active_shipping/rate_estimate.rb', line 83

def estimate_reference
  @estimate_reference
end

#expires_atObject

Returns the value of attribute expires_at.



83
84
85
# File 'lib/active_shipping/rate_estimate.rb', line 83

def expires_at
  @expires_at
end

#insurance_priceInteger

The price of insurance in cents

Returns:

  • (Integer)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#messagesObject

Returns the value of attribute messages.



83
84
85
# File 'lib/active_shipping/rate_estimate.rb', line 83

def messages
  @messages
end

#negotiated_rateInteger

The negotiated rate in cents

Returns:

  • (Integer)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#originActiveShipping::Location

The origin of the shipment



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#package_ratesArray<{:rate => Integer, :package => ActiveShipping::Package}>

A list of rates for all the packages in the shipment

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#phone_requiredBoolean

Specifies if a phone number is required for the shipping rate

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#pickup_timeObject

Returns the value of attribute pickup_time.



83
84
85
# File 'lib/active_shipping/rate_estimate.rb', line 83

def pickup_time
  @pickup_time
end

#service_codeString

The code of the shipping service

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#service_nameString

The name of the shipping service (e.g. 'First Class Ground')

Returns:

  • (String)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#shipment_optionsArray<{ code: String, price: Integer }>

Additional priced options bundled with the given rate estimate with price in cents

Returns:

  • (Array<{ code: String, price: Integer }>)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

#shipping_dateDate

The date on which the shipment will be expected. Normally, this means that the delivery date range can only be promised if the shipment is handed over on or before this date.

Returns:

  • (Date)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/active_shipping/rate_estimate.rb', line 82

class RateEstimate
  attr_accessor :origin, :destination, :package_rates,
              :carrier, :service_name, :service_code, :description,
              :shipping_date, :delivery_date, :delivery_range,
              :currency, :negotiated_rate, :insurance_price,
              :estimate_reference, :expires_at, :pickup_time,
              :compare_price, :phone_required, :delivery_category,
              :shipment_options, :charge_items, :messages

  def initialize(origin, destination, carrier, service_name, options = {})
    self.origin, self.destination, self.carrier, self.service_name = origin, destination, carrier, service_name
    self.service_code = options[:service_code]
    self.description = options[:description]
    self.estimate_reference = options[:estimate_reference]
    self.pickup_time = options[:pickup_time]
    self.expires_at = options[:expires_at]
    if options[:package_rates]
      self.package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
    else
      self.package_rates = Array(options[:packages]).map { |p| {:package => p} }
    end
    self.total_price = options[:total_price]
    self.negotiated_rate = options[:negotiated_rate]
    self.compare_price = options[:compare_price]
    self.phone_required = options[:phone_required]
    self.currency = options[:currency]
    self.delivery_range = options[:delivery_range]
    self.shipping_date = options[:shipping_date]
    self.delivery_date = @delivery_range.last
    self.insurance_price = options[:insurance_price]
    self.delivery_category = options[:delivery_category]
    self.shipment_options = options[:shipment_options] || []
    self.charge_items = options[:charge_items] || []
    self.messages = options[:messages] || []
  end

  # The total price of the shipments in cents.
  # @return [Integer]
  def total_price
    @total_price || @package_rates.sum { |pr| pr[:rate] }
  rescue NoMethodError
    raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
  end
  alias_method :price, :total_price

  # Adds a package to this rate estimate
  # @param package [ActiveShipping::Package] The package to add.
  # @param rate [#cents, Float, String, nil] The rate for this package. This is only required if
  #   there is no total price for this shipment
  # @return [self]
  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

  # The list of packages for which rate estimates are given.
  # @return [Array<ActiveShipping::Package>]
  def packages
    package_rates.map { |p| p[:package] }
  end

  # The number of packages for which rate estimates are given.
  # @return [Integer]
  def package_count
    package_rates.length
  end

  protected

  def delivery_range=(delivery_range)
    @delivery_range = delivery_range ? delivery_range.map { |date| date_for(date) }.compact : []
  end

  def total_price=(total_price)
    @total_price = Package.cents_from(total_price)
  end

  def negotiated_rate=(negotiated_rate)
    @negotiated_rate = negotiated_rate ? Package.cents_from(negotiated_rate) : nil
  end

  def compare_price=(compare_price)
    @compare_price = compare_price ? Package.cents_from(compare_price) : nil
  end

  def currency=(currency)
    @currency = ActiveUtils::CurrencyCode.standardize(currency)
  end

  def phone_required=(phone_required)
    @phone_required = !!phone_required
  end

  def shipping_date=(shipping_date)
    @shipping_date = date_for(shipping_date)
  end

  def insurance_price=(insurance_price)
    @insurance_price = Package.cents_from(insurance_price)
  end

  private

  # Returns a Date object for a given input
  # @param date [String, Date, Time, DateTime, ...] The object to infer a date from.
  # @return [Date, nil] The Date object absed on the input, or `nil` if no date
  #   could be determined.
  def date_for(date)
    date && Date.strptime(date.to_s, "%Y-%m-%d")
  rescue ArgumentError
    nil
  end
end

Instance Method Details

#add(package, rate = nil) ⇒ self

Adds a package to this rate estimate

Parameters:

  • package (ActiveShipping::Package)

    The package to add.

  • rate (#cents, Float, String, nil) (defaults to: nil)

    The rate for this package. This is only required if there is no total price for this shipment

Returns:

  • (self)

Raises:

  • (ArgumentError)


132
133
134
135
136
137
# File 'lib/active_shipping/rate_estimate.rb', line 132

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_countInteger

The number of packages for which rate estimates are given.

Returns:

  • (Integer)


147
148
149
# File 'lib/active_shipping/rate_estimate.rb', line 147

def package_count
  package_rates.length
end

#packagesArray<ActiveShipping::Package>

The list of packages for which rate estimates are given.

Returns:



141
142
143
# File 'lib/active_shipping/rate_estimate.rb', line 141

def packages
  package_rates.map { |p| p[:package] }
end

#total_priceInteger Also known as: price

The total price of the shipments in cents.

Returns:

  • (Integer)


120
121
122
123
124
# File 'lib/active_shipping/rate_estimate.rb', line 120

def total_price
  @total_price || @package_rates.sum { |pr| pr[:rate] }
rescue NoMethodError
  raise ArgumentError.new("RateEstimate must have a total_price set, or have a full set of valid package rates.")
end

#total_price=(total_price) ⇒ Object (protected)



157
158
159
# File 'lib/active_shipping/rate_estimate.rb', line 157

def total_price=(total_price)
  @total_price = Package.cents_from(total_price)
end