Class: Quickbooks::XSD::Group
Overview
Group of elements, so that we can refer to them by nameā¦
Instance Attribute Summary collapse
-
#maxOccurs ⇒ Object
readonly
Returns the value of attribute maxOccurs.
-
#minOccurs ⇒ Object
readonly
Returns the value of attribute minOccurs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
Instance Method Summary collapse
- #<<(something) ⇒ Object
- #children ⇒ Object
- #clone ⇒ Object
- #exists_in?(object) ⇒ Boolean
- #find(key) ⇒ Object
- #include?(key_or_xsd) ⇒ Boolean
- #index(key) ⇒ Object
-
#initialize(attributes = {}) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #items ⇒ Object
- #merge(attributes) ⇒ Object
- #merge!(attributes) ⇒ Object
-
#repeatable?(key) ⇒ 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
include Validations.
Constructor Details
#initialize(attributes = {}) ⇒ Group
Returns a new instance of Group.
7 8 9 10 11 12 13 14 |
# File 'lib/quickbooks/xsd/group.rb', line 7 def initialize(attributes={}) @name = attributes.delete('name') @ref = attributes.delete('ref') @minOccurs = attributes.delete('minOccurs') @maxOccurs = attributes.delete('maxOccurs') @items = attributes.delete(:items) puts "EG Attributes: #{attributes.inspect}" unless attributes.empty? end |
Instance Attribute Details
#maxOccurs ⇒ Object (readonly)
Returns the value of attribute maxOccurs.
5 6 7 |
# File 'lib/quickbooks/xsd/group.rb', line 5 def maxOccurs @maxOccurs end |
#minOccurs ⇒ Object (readonly)
Returns the value of attribute minOccurs.
5 6 7 |
# File 'lib/quickbooks/xsd/group.rb', line 5 def minOccurs @minOccurs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/quickbooks/xsd/group.rb', line 5 def name @name end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
5 6 7 |
# File 'lib/quickbooks/xsd/group.rb', line 5 def ref @ref end |
Instance Method Details
#<<(something) ⇒ Object
20 21 22 |
# File 'lib/quickbooks/xsd/group.rb', line 20 def <<(something) items << something end |
#children ⇒ Object
87 88 89 90 91 |
# File 'lib/quickbooks/xsd/group.rb', line 87 def children children = [] items.map {|i| i.is_a?(Quickbooks::XSD::Element) ? children << i : children.concat(i.children)} children end |
#clone ⇒ Object
40 41 42 |
# File 'lib/quickbooks/xsd/group.rb', line 40 def clone self.class.new('name' => @name, 'ref' => @ref, 'minOccurs' => @minOccurs, 'maxOccurs' => @maxOccurs, :items => items.map {|i| i.clone}) end |
#exists_in?(object) ⇒ Boolean
57 58 59 |
# File 'lib/quickbooks/xsd/group.rb', line 57 def exists_in?(object) items.any? {|i| i.exists_in?(object)} end |
#find(key) ⇒ Object
61 62 63 |
# File 'lib/quickbooks/xsd/group.rb', line 61 def find(key) children.select {|i| i.name == key}[0] end |
#include?(key_or_xsd) ⇒ Boolean
65 66 67 68 69 |
# File 'lib/quickbooks/xsd/group.rb', line 65 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
71 72 73 |
# File 'lib/quickbooks/xsd/group.rb', line 71 def index(key) children.collect {|e| e.name}.index(key.to_s) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/quickbooks/xsd/group.rb', line 36 def inspect items.map {|i| i.inspect}.join end |
#items ⇒ Object
16 17 18 |
# File 'lib/quickbooks/xsd/group.rb', line 16 def items @items ||= [] end |
#merge(attributes) ⇒ Object
24 25 26 |
# File 'lib/quickbooks/xsd/group.rb', line 24 def merge(attributes) self.class.new({'name' => @name, 'ref' => @ref, 'minOccurs' => @minOccurs, 'maxOccurs' => @maxOccurs, :items => items}.merge(attributes)) end |
#merge!(attributes) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/quickbooks/xsd/group.rb', line 28 def merge!(attributes) @name = attributes.delete('name') || @name @ref = attributes.delete('ref') || @ref @minOccurs = attributes.delete('minOccurs') || @minOccurs @maxOccurs = attributes.delete('maxOccurs') || @maxOccurs return self end |
#repeatable?(key) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is allowed more than once in its parent.
76 77 78 |
# File 'lib/quickbooks/xsd/group.rb', line 76 def repeatable?(key) 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.
81 82 83 84 85 |
# File 'lib/quickbooks/xsd/group.rb', line 81 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
include Validations
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/quickbooks/xsd/group.rb', line 45 def validate(object,required=true) # Validate the object's contents puts "#{$DEBUG<<"\t"}Validating CONFORMS TO Group[#{name}]" if $DEBUG # 1) is it required? # 2) do all items exist? # 3) are all items valid? r = items.inject(Valean.new(nil, required, :exists => true)) {|r,i| r << i.validate(object,required?(i)); r} $DEBUG.chop! if $DEBUG puts "#{$DEBUG}\t- #{r}" if $DEBUG r end |