Class: EasyDom

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

Instance Method Summary collapse

Constructor Details

#initialize(obj, debug: false) ⇒ EasyDom

Returns a new instance of EasyDom.



10
11
12
13
14
15
16
# File 'lib/easydom.rb', line 10

def initialize(obj, debug: false)

  @debug = debug

  @e = obj.is_a?(String) ? FreeDom.new(obj).root : obj      

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/easydom.rb', line 18

def method_missing(sym, *args, &block)

  puts "name: %s; args: %s" % [sym, args.inspect] if @debug

  if @e.respond_to? sym then
    puts 'attribute found' if @debug
    @e.method(sym).call(*args)
  else
    e = @e.element(sym.to_s)
    EasyDom.new(e, debug: @debug) if e
  end

end