Sha256: 70dc439f35653dbe152308e387ae1de893957225abd38a3f86c6289b0ed97203

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

module RubyPsigate
  
  class InvalidItemOption < RubyPsigateError; end
  
  class Item
    include NumberValidationMethods
    include HashVariables
    
    hashable %w( ItemID ItemDescription ItemQty ItemPrice )
    
    attr_reader :qty, :price
    attr_accessor :unique_id, :desc
    
    # For hashable
    alias_method :itemid, :unique_id
    alias_method :itemdescription, :desc
    alias_method :itemqty, :qty
    alias_method :itemprice, :price
    
    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
    # End hashable
    
    def initialize(parameters = {})
      @options = []
    end
    
    def qty=(x)
      x = x.to_i
      @qty = validate(x)
    end
    
    def price=(x)
      x = x.to_f
      @price = Money.new(x*100)
    end
    
    def << (item_option)
      raise InvalidItemOption unless item_option.is_a?(RubyPsigate::ItemOption)
      @options << item_option
      return self
    end
    
    def options
      holder = []
      @options.each do |opt|
        holder << opt.instance_variable_get(:@option)
      end
      holder
    end
    
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby_psigate-0.7.8 lib/ruby_psigate/item.rb
ruby_psigate-0.7.7 lib/ruby_psigate/item.rb
ruby_psigate-0.7.6 lib/ruby_psigate/item.rb
ruby_psigate-0.7.5 lib/ruby_psigate/item.rb
ruby_psigate-0.7.4 lib/ruby_psigate/item.rb
ruby_psigate-0.7.3 lib/ruby_psigate/item.rb
ruby_psigate-0.7.2 lib/ruby_psigate/item.rb
ruby_psigate-0.7.1 lib/ruby_psigate/item.rb
ruby_psigate-0.7 lib/ruby_psigate/item.rb