Class: Xpost::Models::Item

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/xpost/models/item.rb

Constant Summary collapse

ITEM_TYPES =
Set[:product, :shipping, :tax, :fee, :insurance, :discount]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Item

Returns a new instance of Item.



16
17
18
19
20
21
22
# File 'lib/xpost/models/item.rb', line 16

def initialize(options = {})
  @type         = options[:type]
  @description  = options[:description]
  @amount       = options[:amount]
  @quantity     = options[:quantity]
  @metadata     = options[:metadata]
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



11
12
13
# File 'lib/xpost/models/item.rb', line 11

def amount
  @amount
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/xpost/models/item.rb', line 11

def description
  @description
end

#metadataObject

Returns the value of attribute metadata.



11
12
13
# File 'lib/xpost/models/item.rb', line 11

def 
  @metadata
end

#quantityObject

Returns the value of attribute quantity.



11
12
13
# File 'lib/xpost/models/item.rb', line 11

def quantity
  @quantity
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/xpost/models/item.rb', line 11

def type
  @type
end

Instance Method Details

#check_item_typeObject



24
25
26
27
28
# File 'lib/xpost/models/item.rb', line 24

def check_item_type
  if self.type.present? && !ITEM_TYPES.include?(self.type.to_sym)
    errors.add(:type, "wrong item type")
  end
end