Class: Saxerator::Latches::WithAttributes

Inherits:
AbstractLatch show all
Defined in:
lib/saxerator/latches/with_attributes.rb

Instance Method Summary collapse

Methods inherited from AbstractLatch

#close, #open, #open?

Methods inherited from SaxHandler

#characters

Constructor Details

#initialize(attrs) ⇒ WithAttributes

Returns a new instance of WithAttributes.



6
7
8
# File 'lib/saxerator/latches/with_attributes.rb', line 6

def initialize(attrs)
  @attrs = attrs
end

Instance Method Details

#end_element(_) ⇒ Object



19
20
21
# File 'lib/saxerator/latches/with_attributes.rb', line 19

def end_element(_)
  close
end

#start_element(_, attributes) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/saxerator/latches/with_attributes.rb', line 10

def start_element(_, attributes)
  attributes = Hash[attributes]
  if @attrs.all? { |k, v| attributes[k] && (v.nil? || attributes[k] == v) }
    open
  else
    close
  end
end