Class: Quickbooks::Property

Inherits:
Object show all
Defined in:
lib/quickbooks/property.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Property

Returns a new instance of Property.

Raises:

  • (RuntimeError)


28
29
30
31
# File 'lib/quickbooks/property.rb', line 28

def initialize(value=nil)
  raise RuntimeError, "Type class '#{self.class.short_name}' has no native class set. This is a BUG. Please report it!" unless self.class.native.is_a?(Class)
  @value = value.is_a?(self.class.native) ? value : self.class.native.new(value)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/quickbooks/property.rb', line 56

def method_missing(method_name, *args, &block)
  if block_given?
    if @value.respond_to?(method_name)
      @value.method(method_name).call(*args) {|*arr| yield *arr }
    else
      args << block
      @value.send(method_name, *args)
    end
  else
    @value.send(method_name, *args)
  end
end

Class Attribute Details

.xsdObject

Returns the value of attribute xsd.



13
14
15
# File 'lib/quickbooks/property.rb', line 13

def xsd
  @xsd
end

Instance Attribute Details

#valueObject Also known as: __value__

Returns the value of attribute value.



22
23
24
# File 'lib/quickbooks/property.rb', line 22

def value
  @value
end

Class Method Details

.nativeObject



15
16
17
# File 'lib/quickbooks/property.rb', line 15

def native
  @native ||= Quickbooks::Types.const_get(xsd.type.name)
end

.pluralizeObject



9
10
11
# File 'lib/quickbooks/property.rb', line 9

def self.pluralize
  Quickbooks::Properties
end

Instance Method Details

#eql?(value) ⇒ Boolean Also known as: ===

Returns:



33
34
35
# File 'lib/quickbooks/property.rb', line 33

def eql?(value)
  @value.eql?(value)
end

#inspectObject



42
43
44
# File 'lib/quickbooks/property.rb', line 42

def inspect
  "#{self.class.short_name}[#{@value.class.short_name.gsub(/type$/,'')}]=#{@value.inspect}"
end

#nil?Boolean

Returns:



38
39
40
# File 'lib/quickbooks/property.rb', line 38

def nil?
  @value.nil?
end

#to_dirty_xml(include_required = false) ⇒ Object



52
53
54
# File 'lib/quickbooks/property.rb', line 52

def to_dirty_xml(include_required=false)
  to_xml
end

#to_sObject



46
47
48
# File 'lib/quickbooks/property.rb', line 46

def to_s
  @value.to_s
end

#to_xmlObject



49
50
51
# File 'lib/quickbooks/property.rb', line 49

def to_xml
  '<' + self.class.short_name + '>' + @value.to_xml + '</' + self.class.short_name + '>'
end