Class: Saxerator::Latches::ChildOf

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/saxerator/latches/child_of.rb

Instance Method Summary collapse

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



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

Returns:

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