Class: ActiveShipping::NewZealandPost::NewZealandPostPackage

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

Instance Method Summary collapse

Constructor Details

#initialize(package, api) ⇒ NewZealandPostPackage

Returns a new instance of NewZealandPostPackage.



191
192
193
194
195
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 191

def initialize(package, api)
  @package = package
  @api = api
  @params = { :weight => weight, :length => length }
end

Instance Method Details

#api_paramsObject (protected)



224
225
226
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 224

def api_params
  send("#{@api}_params")
end

#cuboid_paramsObject (protected)



240
241
242
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 240

def cuboid_params
  { :height => height, :thickness => width }
end

#currencyObject (protected)



257
258
259
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 257

def currency
  @package.currency || "NZD"
end

#cylinder_paramsObject (protected)



244
245
246
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 244

def cylinder_params
  { :diameter => width }
end

#domestic_paramsObject (protected)



232
233
234
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 232

def domestic_params
  {}
end

#heightObject (protected)



211
212
213
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 211

def height
  mm(:height)
end

#international_paramsObject (protected)



228
229
230
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 228

def international_params
  { :value => value }
end

#lengthObject (protected)



207
208
209
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 207

def length
  mm(:length)
end

#mm(measurement) ⇒ Object (protected)



248
249
250
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 248

def mm(measurement)
  @package.cm(measurement) * 10
end

#paramsObject



197
198
199
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 197

def params
  @params.merge(api_params).merge(shape_params)
end

#shapeObject (protected)



219
220
221
222
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 219

def shape
  return :cylinder if @package.cylinder?
  :cuboid
end

#shape_paramsObject (protected)



236
237
238
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 236

def shape_params
  send("#{shape}_params")
end

#valueObject (protected)



252
253
254
255
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 252

def value
  return 0 unless @package.value && currency == "NZD"
  @package.value / 100
end

#weightObject (protected)



203
204
205
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 203

def weight
  @package.kg
end

#widthObject (protected)



215
216
217
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 215

def width
  mm(:width)
end