Class: Celerity::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/celerity/identifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, attributes = {}) ⇒ Identifier

Returns a new instance of Identifier.



7
8
9
10
11
# File 'lib/celerity/identifier.rb', line 7

def initialize(tag, attributes = {})
  @tag        = tag
  @attributes = attributes
  @text       = nil
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/celerity/identifier.rb', line 5

def attributes
  @attributes
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/celerity/identifier.rb', line 5

def tag
  @tag
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/celerity/identifier.rb', line 4

def text
  @text
end

Instance Method Details

#match?(element) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/celerity/identifier.rb', line 13

def match?(element)
  return false unless @tag == element.getTagName

  attr_result = @attributes.all? do |key, values|
    values.any? { |val| Util.matches?(element.getAttribute(key.to_s), val) }
  end

  if @text
    attr_result && Util.matches?(element.asText.strip, @text)
  else
    attr_result
  end
end