Class: Saxerator::Latches::ChildOf
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Saxerator::Latches::ChildOf
- Defined in:
- lib/saxerator/latches/child_of.rb
Instance Method Summary collapse
- #depth_within_element ⇒ Object
- #end_element(_) ⇒ Object
- #increment_depth(amount) ⇒ Object
-
#initialize(name) ⇒ ChildOf
constructor
A new instance of ChildOf.
- #open? ⇒ Boolean
- #start_element(name, _) ⇒ Object
Constructor Details
#initialize(name) ⇒ ChildOf
Returns a new instance of ChildOf.
4 5 6 7 |
# File 'lib/saxerator/latches/child_of.rb', line 4 def initialize(name) @name = name @depths = [] end |
Instance Method Details
#depth_within_element ⇒ Object
33 34 35 |
# File 'lib/saxerator/latches/child_of.rb', line 33 def depth_within_element @depths.size > 0 ? @depths.last : 0 end |
#end_element(_) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/saxerator/latches/child_of.rb', line 18 def end_element _ if depth_within_element > 0 increment_depth(-1) @depths.pop if @depths.last == 0 end end |
#increment_depth(amount) ⇒ Object
29 30 31 |
# File 'lib/saxerator/latches/child_of.rb', line 29 def increment_depth(amount) @depths.map! { |depth| depth + amount } end |
#open? ⇒ Boolean
25 26 27 |
# File 'lib/saxerator/latches/child_of.rb', line 25 def open? depth_within_element == 2 end |
#start_element(name, _) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/saxerator/latches/child_of.rb', line 9 def start_element name, _ if depth_within_element > 0 increment_depth(1) end if @name == name @depths.push 1 end end |