Class: ShippingScale::Package

Inherits:
Packaging show all
Defined in:
lib/shipping_scale/packaging/package.rb

Instance Attribute Summary collapse

Attributes inherited from Packaging

#packages, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packaging

#details, #get_price!, #price

Constructor Details

#initialize(**options) ⇒ Package

Returns a new instance of Package.



22
23
24
25
26
27
28
29
30
# File 'lib/shipping_scale/packaging/package.rb', line 22

def initialize(**options)
  @weight = options[:weight]
  @pounds = (options[:pounds]) ? options[:pounds] : get_pounds
  @ounces = (options[:ounces]) ? options[:ounces] : get_ounces
  @zip_origination = (options[:zip_origination]) ? options[:zip_origination] : ShippingScale.config.zip_origination 
  @zip_destination = (options[:zip_destination]) ? options[:zip_destination] : ShippingScale.config.zip_destination

  @packages = [self]
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def height
  @height
end

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def length
  @length
end

#ouncesObject (readonly)

Returns the value of attribute ounces.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def ounces
  @ounces
end

#poundsObject (readonly)

Returns the value of attribute pounds.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def pounds
  @pounds
end

#weightObject (readonly)

Returns the value of attribute weight.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def weight
  @weight
end

#widthObject (readonly)

Returns the value of attribute width.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def width
  @width
end

#zip_originationObject (readonly)

Returns the value of attribute zip_origination.



11
12
13
# File 'lib/shipping_scale/packaging/package.rb', line 11

def zip_origination
  @zip_origination
end

Class Method Details

.shipment(details) ⇒ Object



5
6
7
8
# File 'lib/shipping_scale/packaging/package.rb', line 5

def shipment(details)
  packages = details.map { |package| new(package) }
  ShippingScale::Shipment.new(packages)
end

Instance Method Details

#build_xml(package) ⇒ Object



32
33
34
35
36
# File 'lib/shipping_scale/packaging/package.rb', line 32

def build_xml(package) 
  attrs.each do |k, v| 
    package.tag!(k.to_s.upper_camelcase, v) 
  end
end