Class: Nokogiri::XML::Schematron::Base Abstract
- Inherits:
-
Object
- Object
- Nokogiri::XML::Schematron::Base
- Defined in:
- lib/nokogiri/xml/schematron/base.rb
Overview
The base class for internal representations of Schematron types.
Instance Attribute Summary collapse
-
#children ⇒ Array<Nokogiri::XML::Schematron::Base>
readonly
The children of the internal representation of the Schematron type.
-
#options ⇒ Hash<Symbol, Object>
readonly
The options.
-
#parent ⇒ Nokogiri::XML::Schematron::Base
readonly
The parent object.
Class Method Summary collapse
-
.attribute(name, **options) ⇒ void
Defines methods for a named XML attribute.
-
.element(name, klass) ⇒ void
Defines methods for a named XML element.
Instance Method Summary collapse
-
#initialize(parent, **options) {|base| ... } ⇒ Base
constructor
Create a new
Base
object. -
#to_builder(*args, **options) ⇒ Nokogiri::XML::Builder
Convert this
Base
object to aBuilder
object.
Constructor Details
#initialize(parent, **options) {|base| ... } ⇒ Base
Create a new Base
object.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 92 def initialize(parent, **, &block) @parent = parent @children = [] @options = if block_given? case block.arity when 1 then block.call(self) else instance_eval(&block) end end end |
Instance Attribute Details
#children ⇒ Array<Nokogiri::XML::Schematron::Base> (readonly)
Returns the children of the internal representation of the Schematron type.
81 82 83 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 81 def children @children end |
#options ⇒ Hash<Symbol, Object> (readonly)
Returns the options.
84 85 86 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 84 def @options end |
#parent ⇒ Nokogiri::XML::Schematron::Base (readonly)
Returns the parent object.
78 79 80 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 78 def parent @parent end |
Class Method Details
.attribute(name, **options) ⇒ void
This method returns an undefined value.
Defines methods for a named XML attribute.
For example:
attribute :name
defines reader and writer methods that are equivalent to:
def name
@options[:name]
end
def name=(value)
@options[:name] = value
end
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 31 def attribute(name, **) unless [:reader] == false define_method(name.to_sym) do instance_variable_get(:@options).send(:[], name.to_sym) end end unless [:writer] == false define_method(:"#{name.to_sym}=") do |value| instance_variable_get(:@options).send(:[]=, name.to_sym, value) end end return end |
.element(name, klass) ⇒ void
This method returns an undefined value.
Defines methods for a named XML element.
For example:
element :name, DescendentOfBase
where
class DescendentOfBase < Base; end
is a descendent of this class, defines methods that are equivalent to:
def name(*args, **, &block)
base = DescendentOfBase.new(self, *args, **, &block)
@children << base
base
end
68 69 70 71 72 73 74 |
# File 'lib/nokogiri/xml/schematron/base.rb', line 68 def element(name, klass) define_method(name.to_sym) do |*args, **, &block| base = klass.send(:new, self, *args, **, &block) instance_variable_get(:@children) << base base end end |