Class: Quickbooks::XSD::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/quickbooks/xsd/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
11
12
13
# File 'lib/quickbooks/xsd/attribute.rb', line 7

def initialize(attributes)
  @name = attributes.delete('name')
  @type = attributes.delete('type')
  @use  = attributes.delete('use')
  @default = attributes.delete('default')
  warn "!! Unhandled Attribute attributes: #{attributes.keys.join(', ')}" if !attributes.empty?
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



4
5
6
# File 'lib/quickbooks/xsd/attribute.rb', line 4

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/quickbooks/xsd/attribute.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/quickbooks/xsd/attribute.rb', line 5

def type
  @type
end

#useObject (readonly)

Returns the value of attribute use.



4
5
6
# File 'lib/quickbooks/xsd/attribute.rb', line 4

def use
  @use
end

Instance Method Details

#<<(something) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/quickbooks/xsd/attribute.rb', line 19

def <<(something)
  case something
  when SimpleType
    self.type = something
  else
    items << something
  end
end

#childrenObject



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

def children
  []
end

#include?(key_or_xsd) ⇒ Boolean

Returns:



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

def include?(key_or_xsd)
  false
end

#inspectObject



41
42
43
# File 'lib/quickbooks/xsd/attribute.rb', line 41

def inspect
  "<Attribute: '#{name}' #{use if use} #{type.inspect} #{"default="+default.inspect if default}>".gsub(/  +/,' ').gsub(/ >/,'>')
end

#itemsObject



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

def items
  @items ||= []
end

#required?(key_or_xsd = nil) ⇒ Boolean

Reports whether the named Quickbooks::XSD::Element or other xsd object is required within its container.

Returns:



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

def required?(key_or_xsd=nil)
  @use == 'required'
end

#validate(object, required = true) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/quickbooks/xsd/attribute.rb', line 28

def validate(object,required=true)
  return Valean.perfect!(name, required) if object.is_a?(Quickbooks::Model)
  # Validate the object's contents
  puts "#{$DEBUG<<"\t"}Validating #{required ? 'REQUIRED' : 'OPTIONAL'} Attribute #{name}" if $DEBUG
  # A) am I required?
  # B) do I exist?
  # TODO: Also validate by @type
  r = Valean.new(name, required, :exists => !object[name].nil?)
  $DEBUG.chop! if $DEBUG
  puts "#{$DEBUG}\t- #{r}" if $DEBUG
  r
end