Module: Xommelier::Xml::Element::Structure::ClassMethods
- Defined in:
- lib/xommelier/xml/element/structure.rb
Instance Method Summary collapse
- #any(&block) ⇒ Object
-
#attribute(name, options = {}) ⇒ Object
Defines containing attribute.
-
#element(name, options = {}) ⇒ Object
Defines containing element.
- #inherited(child) ⇒ Object
- #many(&block) ⇒ Object
- #may(&block) ⇒ Object
-
#text ⇒ Object
Defines containing text.
Instance Method Details
#any(&block) ⇒ Object
113 114 115 |
# File 'lib/xommelier/xml/element/structure.rb', line 113 def any(&block) (count: :any) { |any| any.instance_eval(&block) } end |
#attribute(name, options = {}) ⇒ Object
Defines containing attribute
102 103 104 105 106 |
# File 'lib/xommelier/xml/element/structure.rb', line 102 def attribute(name, = {}) [:ns] ||= xmlns attributes[name] = Attribute.new(name, ) define_attribute_accessors(name) end |
#element(name, options = {}) ⇒ Object
Defines containing element
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/xommelier/xml/element/structure.rb', line 60 def element(name, = {}) # Set name, type and element name by reference if provided if name.is_a?(Hash) = name name = nil end # Set type and element name from reference if .key?(:ref) raise "#{[:ref]} is not subclass of Xommelier::Element" unless referenceable?([:ref]) [:type] = .delete(:ref) # Set element name from provided complex type [:as] ||= [:type].element_name # Set attribute name from element name name ||= [:as].underscore.to_sym end # Try to define element name from [:as] ||= name.to_s.camelize(:lower) # Set namespace from element type or wrapper xmlns [:ns] ||= if referenceable?([:type]) [:type].xmlns else xmlns end if [:fixed] [:default] = [:fixed] [:count] = :one end element = Element.new(name, ) elements[name] = element define_element_accessors(element) end |
#inherited(child) ⇒ Object
52 53 54 55 |
# File 'lib/xommelier/xml/element/structure.rb', line 52 def inherited(child) child.elements = elements.dup child.attributes = attributes.dup end |
#many(&block) ⇒ Object
117 118 119 |
# File 'lib/xommelier/xml/element/structure.rb', line 117 def many(&block) (count: :many) { |many| many.instance_eval(&block) } end |
#may(&block) ⇒ Object
121 122 123 |
# File 'lib/xommelier/xml/element/structure.rb', line 121 def may(&block) (count: :may) { |may| may.instance_eval(&block) } end |
#text ⇒ Object
Defines containing text
109 110 111 |
# File 'lib/xommelier/xml/element/structure.rb', line 109 def text(*) define_text_accessors end |