Class: HtmlAide::Element
- Inherits:
-
Object
- Object
- HtmlAide::Element
- Defined in:
- lib/html_aide/element.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Instance Method Summary collapse
- #attributes ⇒ Object
- #children ⇒ Object
-
#initialize(node) ⇒ Element
constructor
A new instance of Element.
- #name ⇒ Object
- #text ⇒ Object
- #to_s ⇒ Object
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
#proxy ⇒ Object (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
#attributes ⇒ Object
14 15 16 |
# File 'lib/html_aide/element.rb', line 14 def attributes proxy.attributes end |
#children ⇒ Object
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 |
#name ⇒ Object
10 11 12 |
# File 'lib/html_aide/element.rb', line 10 def name proxy.name end |
#text ⇒ Object
18 19 20 |
# File 'lib/html_aide/element.rb', line 18 def text @text ||= Nokogiri::HTML.parse(@markup).text.strip end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/html_aide/element.rb', line 22 def to_s @markup end |