Class: Saxerator::Latches::ChildOf

Inherits:
SaxHandler show all
Defined in:
lib/saxerator/latches/child_of.rb

Instance Method Summary collapse

Methods inherited from SaxHandler

#characters

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_elementObject



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

Returns:

  • (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