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.



189
190
191
192
193
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 189

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

Instance Method Details

#api_paramsObject (protected)



222
223
224
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 222

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

#cuboid_paramsObject (protected)



238
239
240
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 238

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

#currencyObject (protected)



255
256
257
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 255

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

#cylinder_paramsObject (protected)



242
243
244
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 242

def cylinder_params
  { :diameter => width }
end

#domestic_paramsObject (protected)



230
231
232
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 230

def domestic_params
  {}
end

#heightObject (protected)



209
210
211
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 209

def height
  mm(:height)
end

#international_paramsObject (protected)



226
227
228
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 226

def international_params
  { :value => value }
end

#lengthObject (protected)



205
206
207
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 205

def length
  mm(:length)
end

#mm(measurement) ⇒ Object (protected)



246
247
248
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 246

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

#paramsObject



195
196
197
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 195

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

#shapeObject (protected)



217
218
219
220
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 217

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

#shape_paramsObject (protected)



234
235
236
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 234

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

#valueObject (protected)



250
251
252
253
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 250

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

#weightObject (protected)



201
202
203
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 201

def weight
  @package.kg
end

#widthObject (protected)



213
214
215
# File 'lib/active_shipping/carriers/new_zealand_post.rb', line 213

def width
  mm(:width)
end