Class: Quickbooks::XSD::Union
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #<<(something) ⇒ Object
- #children ⇒ Object
- #clone ⇒ Object
- #find(key) ⇒ Object
- #include?(key_or_xsd) ⇒ Boolean
- #index(key) ⇒ Object
-
#initialize(attributes) ⇒ Union
constructor
A new instance of Union.
- #inspect ⇒ Object
- #items ⇒ Object
-
#repeatable?(key = nil) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is allowed more than once in its parent.
-
#required?(key_or_xsd) ⇒ 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) ⇒ Union
Returns a new instance of Union.
6 7 8 9 |
# File 'lib/quickbooks/xsd/union.rb', line 6 def initialize(attributes) @items = attributes.delete(:items) puts "More attributes for Union: #{attributes.inspect}" unless attributes.empty? end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/quickbooks/xsd/union.rb', line 4 def type @type end |
Instance Method Details
#<<(something) ⇒ Object
15 16 17 |
# File 'lib/quickbooks/xsd/union.rb', line 15 def <<(something) items << something end |
#children ⇒ Object
63 64 65 66 67 |
# File 'lib/quickbooks/xsd/union.rb', line 63 def children children = [] items.map {|i| i.is_a?(Quickbooks::XSD::Element) ? children << i : children.concat(i.children)} children end |
#clone ⇒ Object
19 20 21 |
# File 'lib/quickbooks/xsd/union.rb', line 19 def clone self.class.new(:items => items.map {|i| i.clone}) end |
#find(key) ⇒ Object
37 38 39 |
# File 'lib/quickbooks/xsd/union.rb', line 37 def find(key) children.select {|i| i.name == key}[0] end |
#include?(key_or_xsd) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/quickbooks/xsd/union.rb', line 41 def include?(key_or_xsd) key_or_xsd.is_a?(String) ? children.collect {|e| e.name}.include?(key_or_xsd) : (key_or_xsd == self || items.any? {|i| i.include?(key_or_xsd)}) end |
#index(key) ⇒ Object
47 48 49 |
# File 'lib/quickbooks/xsd/union.rb', line 47 def index(key) children.collect {|e| e.name}.index(key.to_s) end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/quickbooks/xsd/union.rb', line 23 def inspect "#{@items.map {|i| i.inspect}.join(' or ')}" end |
#items ⇒ Object
11 12 13 |
# File 'lib/quickbooks/xsd/union.rb', line 11 def items @items ||= [] end |
#repeatable?(key = nil) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is allowed more than once in its parent.
52 53 54 |
# File 'lib/quickbooks/xsd/union.rb', line 52 def repeatable?(key=nil) items.any? {|i| i.include?(key) && i.repeatable?(key)} end |
#required?(key_or_xsd) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is required within its container.
57 58 59 60 61 |
# File 'lib/quickbooks/xsd/union.rb', line 57 def required?(key_or_xsd) key_or_xsd.is_a?(String) ? items.any? {|i| i.include?(key_or_xsd) && i.required?(key_or_xsd)} : (key_or_xsd == self || items.select {|i| i.include?(key_or_xsd)}.any? {|i| i.required?(key_or_xsd)}) end |
#validate(object, required = true) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/quickbooks/xsd/union.rb', line 27 def validate(object,required=true) # Validate the object's contents puts "#{$DEBUG<<"\t"}Validating #{object.to_s} CONFORMS TO #Union" if $DEBUG r = Valean.new r.invalid!("invalid value") unless items.collect {|i| i.validate(object)}.any? {|i| i.exists? && i.valid?} $DEBUG.chop! if $DEBUG puts "#{$DEBUG}\t- #{r}" if $DEBUG r end |