Class: Gammo::XPath::AST::NodeTest::Name

Inherits:
Gammo::XPath::AST::NodeTest
  • Object
show all
Defined in:
lib/gammo/xpath/ast/node_test.rb

Constant Summary

Constants included from Subclassify

Subclassify::NotFoundError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local: nil, namespace: nil) ⇒ Name

Returns a new instance of Name.



20
21
22
23
# File 'lib/gammo/xpath/ast/node_test.rb', line 20

def initialize(local: nil, namespace: nil)
  @local = local
  @namespace = namespace
end

Instance Attribute Details

#localObject (readonly)

Returns the value of attribute local.



18
19
20
# File 'lib/gammo/xpath/ast/node_test.rb', line 18

def local
  @local
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



18
19
20
# File 'lib/gammo/xpath/ast/node_test.rb', line 18

def namespace
  @namespace
end

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gammo/xpath/ast/node_test.rb', line 29

def match?(node)
  return false unless node
  return false if xml_namespace?
  return !namespace || namespace == node.namespace if local == ?*
  # TODO: investigate
  if node.instance_of?(Gammo::Attribute)
    # TODO: need to work
    node.key == local && node.namespace == namespace
  else
    if document = node.owner_document
      # TODO: ignoring ascii case
      return node.tag == local && (!namespace || node.namespace == namespace) if node.instance_of?(Gammo::Node::Element)
      return node.tag == local && node.namespace == namespace && namespace
    end
    node.tag == local && node.namespace == namespace
  end
end

#xml_namespace?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gammo/xpath/ast/node_test.rb', line 25

def xml_namespace?
  namespace == 'http://www.w3.org/XML/1998/namespace'
end