Class: Habaki::Visitor::NokogiriElement
- Defined in:
- lib/habaki/visitor/nokogiri_element.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attr(key) ⇒ Object
- #children ⇒ Object
- #class_name ⇒ Object
- #id_name ⇒ Object
-
#initialize(element) ⇒ NokogiriElement
constructor
A new instance of NokogiriElement.
- #parent ⇒ Object
- #previous ⇒ Object
- #tag_name ⇒ Object
- #text ⇒ Object
- #traverse(&block) ⇒ Object
Constructor Details
#initialize(element) ⇒ NokogiriElement
Returns a new instance of NokogiriElement.
6 7 8 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 6 def initialize(element) @element = element end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
4 5 6 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 4 def element @element end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 51 def ==(other) @element == other.element end |
#attr(key) ⇒ Object
22 23 24 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 22 def attr(key) @element[key] end |
#children ⇒ Object
38 39 40 41 42 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 38 def children @element.children.map do |child| child.is_a?(Nokogiri::XML::Element) ? Visitor::NokogiriElement.new(child) : nil end.compact end |
#class_name ⇒ Object
14 15 16 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 14 def class_name @element["class"] end |
#id_name ⇒ Object
18 19 20 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 18 def id_name @element["id"] end |
#parent ⇒ Object
30 31 32 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 30 def parent Visitor::NokogiriElement.new(@element.parent) if @element.respond_to?(:parent) end |
#previous ⇒ Object
34 35 36 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 34 def previous Visitor::NokogiriElement.new(@element.previous_element) if @element.respond_to?(:previous_element) && @element.previous_element end |
#tag_name ⇒ Object
10 11 12 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 10 def tag_name @element.name end |
#text ⇒ Object
26 27 28 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 26 def text @element.text end |
#traverse(&block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/habaki/visitor/nokogiri_element.rb', line 44 def traverse &block @element.traverse do |el| next unless el.is_a?(Nokogiri::XML::Element) block.call Visitor::NokogiriElement.new(el) end end |