Class: Quickbooks::XSD::SimpleType
- Defined in:
- lib/quickbooks/xsd/simple_type.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#restriction ⇒ Object
Returns the value of attribute restriction.
-
#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 = {}) ⇒ SimpleType
constructor
A new instance of SimpleType.
- #inspect ⇒ Object
- #merge(attributes) ⇒ Object
- #merge!(simple_type) ⇒ 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
Constructor Details
#initialize(attributes = {}) ⇒ SimpleType
Returns a new instance of SimpleType.
13 14 15 16 17 18 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 13 def initialize(attributes={}) @name = attributes.delete('name') @type = attributes.delete(:type) @restriction = attributes.delete(:restriction) warn "!! Unhandled simple type attributes: #{attributes.keys.join(', ')}" if !attributes.empty? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 6 def name @name end |
#restriction ⇒ Object
Returns the value of attribute restriction.
7 8 9 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 7 def restriction @restriction end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 7 def type @type end |
Instance Method Details
#<<(something) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 20 def <<(something) case something when Union self.type = something else warn "Something (#{something.inspect}) not handled by #{inspect}" end end |
#children ⇒ Object
82 83 84 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 82 def children type ? type.children : [] end |
#clone ⇒ Object
39 40 41 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 39 def clone self.class.new('name' => @name, :type => @type ? @type.clone : nil, :restriction => @restriction ? @restriction.clone : nil) end |
#find(key) ⇒ Object
58 59 60 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 58 def find(key) children.select {|i| i.name == key}[0] end |
#include?(key_or_xsd) ⇒ Boolean
62 63 64 65 66 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 62 def include?(key_or_xsd) key_or_xsd.is_a?(String) ? children.collect {|e| e.name}.include?(key_or_xsd) : (key_or_xsd == self || (type ? type.include?(key_or_xsd) : false)) end |
#index(key) ⇒ Object
68 69 70 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 68 def index(key) children.collect {|e| e.name}.index(key.to_s) end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 43 def inspect "(#{(type || restriction).inspect})" end |
#merge(attributes) ⇒ Object
29 30 31 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 29 def merge(attributes) self.class.new({'name' => @name, :type => @type}.merge(attributes)) end |
#merge!(simple_type) ⇒ Object
33 34 35 36 37 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 33 def merge!(simple_type) @name = simple_type.name || @name @type = simple_type.type || @type self end |
#repeatable?(key) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is allowed more than once in its parent.
73 74 75 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 73 def repeatable?(key) type ? type.repeatable?(key) : false end |
#required?(key_or_xsd) ⇒ Boolean
Reports whether the named Quickbooks::XSD::Element or other xsd object is required within its container.
78 79 80 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 78 def required?(key_or_xsd) key_or_xsd == self || (type ? type.required?(key_or_xsd) : false) end |
#validate(object, required = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/quickbooks/xsd/simple_type.rb', line 47 def validate(object,required=true) # Validate the object's contents puts "#{$DEBUG<<"\t"}Validating #{object.to_s} CONFORMS TO #SimpleType" if $DEBUG r = Valean.new(nil, required, :exists => true) r << type.validate(object) if type r << restriction.validate(object) if restriction $DEBUG.chop! if $DEBUG puts "#{$DEBUG}\t- #{r}" if $DEBUG r end |