Class: ActiveShipping::PackageItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, grams_or_ounces, value, quantity, options = {}) ⇒ PackageItem

Returns a new instance of PackageItem.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_shipping/package_item.rb', line 5

def initialize(name, grams_or_ounces, value, quantity, options = {})
  @name = name

  imperial = (options[:units] == :imperial)

  @unit_system = imperial ? :imperial : :metric

  @weight = grams_or_ounces
  @weight = Measured::Weight.new(grams_or_ounces, (@unit_system == :imperial ? :oz : :g)) unless @weight.is_a?(Measured::Weight)

  @value = Package.cents_from(value)
  @quantity = quantity > 0 ? quantity : 1

  @sku = options[:sku]
  @hs_code = options[:hs_code]
  @options = options
end

Instance Attribute Details

#hs_codeObject (readonly)

Returns the value of attribute hs_code.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def hs_code
  @hs_code
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def options
  @options
end

#quantityObject (readonly)

Returns the value of attribute quantity.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def quantity
  @quantity
end

#skuObject (readonly)

Returns the value of attribute sku.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def sku
  @sku
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def value
  @value
end

#weight(options = {}) ⇒ Object (readonly) Also known as: mass

Returns the value of attribute weight.



3
4
5
# File 'lib/active_shipping/package_item.rb', line 3

def weight
  @weight
end

Instance Method Details

#grams(options = {}) ⇒ Object Also known as: g



43
44
45
# File 'lib/active_shipping/package_item.rb', line 43

def grams(options = {})
  weight(options).convert_to(:g).value
end

#kilograms(options = {}) ⇒ Object Also known as: kg, kgs



54
55
56
# File 'lib/active_shipping/package_item.rb', line 54

def kilograms(options = {})
  weight(options).convert_to(:kg).value
end

#ounces(options = {}) ⇒ Object Also known as: oz



38
39
40
# File 'lib/active_shipping/package_item.rb', line 38

def ounces(options = {})
  weight(options).convert_to(:oz).value
end

#pounds(options = {}) ⇒ Object Also known as: lb, lbs



48
49
50
# File 'lib/active_shipping/package_item.rb', line 48

def pounds(options = {})
  weight(options).convert_to(:lb).value
end