Class: ActiveMerchant::Shipping::PackageItem

Inherits:
Object
  • Object
show all
Includes:
Quantified
Defined in:
lib/active_shipping/shipping/package.rb

Overview

A package item is a unique item(s) that is physically in a package. A single package can have many items. This is only required for shipping methods (label creation) right now.

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


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_shipping/shipping/package.rb', line 11

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

  imperial = (options[:units] == :imperial) ||
             (grams_or_ounces.respond_to?(:unit) && m.unit.to_sym == :imperial)

  @unit_system = imperial ? :imperial : :metric

  @weight = attribute_from_metric_or_imperial(grams_or_ounces, Mass, :grams, :ounces)

  @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


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def hs_code
  @hs_code
end

#nameObject (readonly)

Returns the value of attribute name


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def options
  @options
end

#quantityObject (readonly)

Returns the value of attribute quantity


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def quantity
  @quantity
end

#skuObject (readonly)

Returns the value of attribute sku


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def sku
  @sku
end

#valueObject (readonly)

Returns the value of attribute value


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def value
  @value
end

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

Returns the value of attribute weight


9
10
11
# File 'lib/active_shipping/shipping/package.rb', line 9

def weight
  @weight
end

Instance Method Details

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


49
50
51
# File 'lib/active_shipping/shipping/package.rb', line 49

def grams(options = {})
  weight(options).in_grams.amount
end

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


60
61
62
# File 'lib/active_shipping/shipping/package.rb', line 60

def kilograms(options = {})
  weight(options).in_kilograms.amount
end

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


44
45
46
# File 'lib/active_shipping/shipping/package.rb', line 44

def ounces(options = {})
  weight(options).in_ounces.amount
end

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


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

def pounds(options = {})
  weight(options).in_pounds.amount
end