Class: Nokogiri::XML::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/assert2/xhtml.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

monkey patch me!



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/assert2/xhtml.rb', line 369

def method_missing method, *args, &block # :nodoc:
  if @context && @context.respond_to?(method)
    @context.send(method, *args, &block)
  else
    node = Nokogiri::XML::Node.new(cleanse_element_name(method), @doc) { |n|
      args.each do |arg|
        case arg
        when Hash
          arg.each { |k,v| n[k.to_s] = v.to_s }
        else
          n.content = arg
        end
      end
    }
    insert(node, &block)
  end
end

Instance Method Details

#cleanse_element_name(method) ⇒ Object



365
366
367
# File 'lib/assert2/xhtml.rb', line 365

def cleanse_element_name(method)
  method.to_s.sub(/[_]$/, '') # or [_!]
end