Class: DomRender

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ DomRender

Returns a new instance of DomRender.



12
13
14
# File 'lib/dom_render.rb', line 12

def initialize(s)
  @to_a = render Rexle.new(s).root
end

Instance Attribute Details

#to_aObject (readonly)

Returns the value of attribute to_a.



10
11
12
# File 'lib/dom_render.rb', line 10

def to_a
  @to_a
end

Instance Method Details

#render(x) ⇒ Object



16
17
18
# File 'lib/dom_render.rb', line 16

def render(x)
  method(x.name.to_sym).call(x)
end

#render_all(x) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dom_render.rb', line 20

def render_all(x)

  len = x.children.length - 1

  x.children.map.with_index do |obj,i|

    if obj.is_a? String then
      i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.rstrip.sub(/^\s+/,' ')
    elsif obj.is_a? Rexle::Element
      render obj
    end

  end

end