Class: Quickbooks::XSD::Attribute
- Defined in:
- lib/quickbooks/xsd/attribute.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#use ⇒ Object
readonly
Returns the value of attribute use.
Instance Method Summary collapse
- #<<(something) ⇒ Object
- #children ⇒ Object
- #include?(key_or_xsd) ⇒ Boolean
-
#initialize(attributes) ⇒ Attribute
constructor
A new instance of Attribute.
- #inspect ⇒ Object
- #items ⇒ Object
-
#required?(key_or_xsd = nil) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is required within its container.
- #validate(object, required = true) ⇒ Object
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/quickbooks/xsd/attribute.rb', line 4 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/quickbooks/xsd/attribute.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/quickbooks/xsd/attribute.rb', line 5 def type @type end |
#use ⇒ Object (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 |
#children ⇒ Object
52 53 54 |
# File 'lib/quickbooks/xsd/attribute.rb', line 52 def children [] end |
#include?(key_or_xsd) ⇒ Boolean
49 50 51 |
# File 'lib/quickbooks/xsd/attribute.rb', line 49 def include?(key_or_xsd) false end |
#inspect ⇒ Object
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 |
#items ⇒ Object
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.
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 |