Class: HtmlAide::Element

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

Direct Known Subclasses

NullElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Element

Returns a new instance of Element.



5
6
7
8
# File 'lib/html_aide/element.rb', line 5

def initialize(node)
  @proxy = node
  @markup = Ox.to_xml(node).gsub("\n", '')
end

Instance Attribute Details

#proxyObject (readonly)

Returns the value of attribute proxy.



3
4
5
# File 'lib/html_aide/element.rb', line 3

def proxy
  @proxy
end

Instance Method Details

#attributesObject



14
15
16
# File 'lib/html_aide/element.rb', line 14

def attributes
  proxy.attributes
end

#childrenObject



26
27
28
29
30
31
# File 'lib/html_aide/element.rb', line 26

def children
  @children ||= proxy.nodes.reject {|n|
    String === n}.collect do |node|
    Element.new(node)
  end
end

#nameObject



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

def name
  proxy.name
end

#textObject



18
19
20
# File 'lib/html_aide/element.rb', line 18

def text
  @text ||= Nokogiri::HTML.parse(@markup).text.strip
end

#to_sObject



22
23
24
# File 'lib/html_aide/element.rb', line 22

def to_s
  @markup
end