Class: RubyPsigate::Item

Inherits:
Object
  • Object
show all
Includes:
HashVariables, NumberValidationMethods
Defined in:
lib/ruby_psigate/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashVariables

included

Methods included from NumberValidationMethods

#validate

Constructor Details

#initialize(parameters = {}) ⇒ Item

End hashable



35
36
37
# File 'lib/ruby_psigate/item.rb', line 35

def initialize(parameters = {})
  @options = []
end

Instance Attribute Details

#descObject Also known as: itemdescription

Returns the value of attribute desc.



12
13
14
# File 'lib/ruby_psigate/item.rb', line 12

def desc
  @desc
end

#priceObject Also known as: itemprice

Returns the value of attribute price.



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

def price
  @price
end

#qtyObject Also known as: itemqty

Returns the value of attribute qty.



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

def qty
  @qty
end

#unique_idObject Also known as: itemid

Returns the value of attribute unique_id.



12
13
14
# File 'lib/ruby_psigate/item.rb', line 12

def unique_id
  @unique_id
end

Instance Method Details

#<<(item_option) ⇒ Object

Raises:



49
50
51
52
53
# File 'lib/ruby_psigate/item.rb', line 49

def << (item_option)
  raise InvalidItemOption unless item_option.is_a?(RubyPsigate::ItemOption)
  @options << item_option
  return self
end

#optionsObject



55
56
57
58
59
60
61
# File 'lib/ruby_psigate/item.rb', line 55

def options
  holder = []
  @options.each do |opt|
    holder << opt.instance_variable_get(:@option)
  end
  holder
end

#to_hashObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_psigate/item.rb', line 20

def to_hash
  @return_hash = super
  unless options.count == 0
    @return_hash[:Option] = {} 
    options.each do |opt|
      opt = opt.first
      key = opt[0].to_sym
      value = opt[1]
      @return_hash[:Option][key] = value
    end
  end
  @return_hash
end