Class: Saxerator::Latches::ChildOf
- Inherits:
-
SaxHandler
- Object
- SaxHandler
- 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
Methods inherited from SaxHandler
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
28 29 30 |
# File 'lib/saxerator/latches/child_of.rb', line 28 def depth_within_element !@depths.empty? ? @depths[-1] : 0 end |
#end_element(_) ⇒ Object
14 15 16 17 18 |
# File 'lib/saxerator/latches/child_of.rb', line 14 def end_element(_) return unless depth_within_element > 0 increment_depth(-1) @depths.pop if @depths[-1].zero? end |
#increment_depth(amount) ⇒ Object
24 25 26 |
# File 'lib/saxerator/latches/child_of.rb', line 24 def increment_depth(amount) @depths.map! { |depth| depth + amount } end |
#open? ⇒ Boolean
20 21 22 |
# File 'lib/saxerator/latches/child_of.rb', line 20 def open? depth_within_element == 2 end |
#start_element(name, _) ⇒ Object
9 10 11 12 |
# File 'lib/saxerator/latches/child_of.rb', line 9 def start_element(name, _) increment_depth(1) if depth_within_element > 0 @depths.push 1 if @name == name end |