Class: ActiveShipping::PackageItem
- Inherits:
-
Object
- Object
- ActiveShipping::PackageItem
- Includes:
- Quantified
- Defined in:
- lib/active_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
-
#hs_code ⇒ Object
readonly
Returns the value of attribute hs_code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#sku ⇒ Object
readonly
Returns the value of attribute sku.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#weight(options = {}) ⇒ Object
(also: #mass)
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #grams(options = {}) ⇒ Object (also: #g)
-
#initialize(name, grams_or_ounces, value, quantity, options = {}) ⇒ PackageItem
constructor
A new instance of PackageItem.
- #kilograms(options = {}) ⇒ Object (also: #kg, #kgs)
- #ounces(options = {}) ⇒ Object (also: #oz)
- #pounds(options = {}) ⇒ Object (also: #lb, #lbs)
Constructor Details
#initialize(name, grams_or_ounces, value, quantity, options = {}) ⇒ PackageItem
Returns a new instance of PackageItem.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_shipping/package.rb', line 10 def initialize(name, grams_or_ounces, value, quantity, = {}) @name = name imperial = ([: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 = [:sku] @hs_code = [:hs_code] @options = end |
Instance Attribute Details
#hs_code ⇒ Object (readonly)
Returns the value of attribute hs_code.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def hs_code @hs_code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def @options end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def quantity @quantity end |
#sku ⇒ Object (readonly)
Returns the value of attribute sku.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def sku @sku end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def value @value end |
#weight(options = {}) ⇒ Object (readonly) Also known as: mass
Returns the value of attribute weight.
8 9 10 |
# File 'lib/active_shipping/package.rb', line 8 def weight @weight end |
Instance Method Details
#grams(options = {}) ⇒ Object Also known as: g
48 49 50 |
# File 'lib/active_shipping/package.rb', line 48 def grams( = {}) weight().in_grams.amount end |
#kilograms(options = {}) ⇒ Object Also known as: kg, kgs
59 60 61 |
# File 'lib/active_shipping/package.rb', line 59 def kilograms( = {}) weight().in_kilograms.amount end |
#ounces(options = {}) ⇒ Object Also known as: oz
43 44 45 |
# File 'lib/active_shipping/package.rb', line 43 def ounces( = {}) weight().in_ounces.amount end |
#pounds(options = {}) ⇒ Object Also known as: lb, lbs
53 54 55 |
# File 'lib/active_shipping/package.rb', line 53 def pounds( = {}) weight().in_pounds.amount end |