Class: Xpost::Item
- Inherits:
-
Object
- Object
- Xpost::Item
- Includes:
- ActiveModel::Model
- Defined in:
- lib/xpost/item.rb
Constant Summary collapse
- ITEM_TYPES =
Set[:product, :shipping, :tax, :fee, :insurance, :discount]
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#description ⇒ Object
Returns the value of attribute description.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#product_type ⇒ Object
Returns the value of attribute product_type.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
Instance Method Summary collapse
- #attributes ⇒ Object
- #check_item_type ⇒ Object
-
#initialize(options = {}) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(options = {}) ⇒ Item
Returns a new instance of Item.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/xpost/item.rb', line 15 def initialize( = {}) # Product Type @product_type = .key?(:product_type) ? [:product_type] : "product" # Product Description @description = [:description] # (Single) Product Amount @amount = [:amount] # Product Quantity @quantity = .key?(:quantity) ? [:quantity].to_i : 1 # Additional Product Data (For third-party purposes) @metadata = [:metadata] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
10 11 12 |
# File 'lib/xpost/item.rb', line 10 def amount @amount end |
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/xpost/item.rb', line 10 def description @description end |
#metadata ⇒ Object
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/xpost/item.rb', line 10 def @metadata end |
#product_type ⇒ Object
Returns the value of attribute product_type.
10 11 12 |
# File 'lib/xpost/item.rb', line 10 def product_type @product_type end |
#quantity ⇒ Object
Returns the value of attribute quantity.
10 11 12 |
# File 'lib/xpost/item.rb', line 10 def quantity @quantity end |
Instance Method Details
#attributes ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/xpost/item.rb', line 34 def attributes { type: self.product_type, description: self.description, amount: self.amount, quantity: self.quantity, metadata: self. } end |
#check_item_type ⇒ Object
28 29 30 31 32 |
# File 'lib/xpost/item.rb', line 28 def check_item_type if self.product_type.present? && !ITEM_TYPES.include?(self.product_type.to_sym) errors.add(:type, "wrong item type") end end |