Class: Nokogiri::XML::Builder::NodeBuilder
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/nokogiri/xml/builder.rb |
Class Method Summary
- .new(node, doc_builder) ⇒ NodeBuilder constructor
Instance Method Summary
Constructor Details
.new(node, doc_builder) ⇒ NodeBuilder
# File 'lib/nokogiri/xml/builder.rb', line 443
def initialize(node, doc_builder) @node = node @doc_builder = doc_builder end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block)
[ GitHub ]# File 'lib/nokogiri/xml/builder.rb', line 456
def method_missing(method, *args, &block) opts = args.last.is_a?(Hash) ? args.pop : {} case method.to_s when /^(.*)!$/ @node["id"] = Regexp.last_match(1) @node.content = args.first if args.first when /^(.*)=/ @node[Regexp.last_match(1)] = args.first else @node["class"] = ((@node["class"] || "").split(/\s/) + [method.to_s]).join(" ") @node.content = args.first if args.first end # Assign any extra options opts.each do |k, v| @node[k.to_s] = ((@node[k.to_s] || "").split(/\s/) + [v]).join(" ") end if block old_parent = @doc_builder.parent @doc_builder.parent = @node arity = @doc_builder.arity || block.arity value = if arity <= 0 @doc_builder.instance_eval(&block) else yield(@doc_builder) end @doc_builder.parent = old_parent return value end self end
Instance Method Details
#[](k)
[ GitHub ]# File 'lib/nokogiri/xml/builder.rb', line 452
def [](k) @node[k] end
#[]=(k, v)
[ GitHub ]# File 'lib/nokogiri/xml/builder.rb', line 448
def []=(k, v) @node[k] = v end