Class: Saxon::QName
- Inherits:
-
Object
- Object
- Saxon::QName
- Defined in:
- lib/saxon/qname.rb
Overview
Represents QNames
Defined Under Namespace
Classes: PrefixedStringWithoutNSURIError
Class Method Summary collapse
-
.clark(clark_string) ⇒ Saxon::QName
Create a QName from a Clark-notation string.
-
.create(opts = {}) ⇒ Saxon::QName
Create a QName from prefix, uri, and local name options.
-
.eqname(eqname_string) ⇒ Saxon::QName
Create a QName from an Expanded QName string.
-
.resolve(qname_or_string, namespaces = {}) ⇒ Saxon::QName
Resolve a QName string into a QName.
-
.resolve_qname_string(qname_string, namespaces = {}) ⇒ Saxon::QName
Resolve a QName string of the form “prefix:local-name” into a QName by looking up the namespace URI in a hash of
"prefix" => "namespace-uri"
.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare this QName with another.
-
#clark ⇒ String
Return a Clark notation representation of the QName:.
-
#eqname ⇒ String
Return a Extended QName notation representation of the QName:.
-
#hash ⇒ Object
Compute a hash-code for this QName.
-
#initialize(s9_qname) ⇒ QName
constructor
private
A new instance of QName.
-
#inspect ⇒ Object
Returns a more detailed string representation of the object, showing prefix, uri, and local_name instance variables.
-
#local_name ⇒ String
The local name part of the QName.
-
#prefix ⇒ String
The prefix part of the QName (” if unset).
-
#to_java ⇒ Saxon::S9API::QName
The underlying Saxon QName object.
-
#to_s ⇒ Object
convert the QName to a lexical string, using the prefix (if there is one).
-
#uri ⇒ String
The namespace URI part of the QName (” if unset).
Constructor Details
#initialize(s9_qname) ⇒ QName
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of QName.
97 98 99 |
# File 'lib/saxon/qname.rb', line 97 def initialize(s9_qname) @s9_qname = s9_qname end |
Class Method Details
.clark(clark_string) ⇒ Saxon::QName
Create a Saxon::QName from a Clark-notation string.
Clark-notation for QNames uses {} to delimit the namespace, so for a QName not in a namespace it’s simply local-name
, and for one in a namespace it’s {example.org/ns}local-name
14 15 16 17 |
# File 'lib/saxon/qname.rb', line 14 def self.clark(clark_string) s9_qname = Saxon::S9API::QName.fromClarkName(clark_string) new(s9_qname) end |
.create(opts = {}) ⇒ Saxon::QName
Create a Saxon::QName from prefix, uri, and local name options
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/saxon/qname.rb', line 39 def self.create(opts = {}) prefix = opts[:prefix] uri = opts[:uri] begin local_name = opts.fetch(:local_name) rescue KeyError raise ArgumentError, "The :local_name option must be passed" end s9_qname = Saxon::S9API::QName.new(*[prefix, uri, local_name].compact) new(s9_qname) end |
.eqname(eqname_string) ⇒ Saxon::QName
Create a Saxon::QName from an Expanded QName string.
Expanded QNames uses Q{} to delimit the namespace, so for a QName not in a namespace it’s simply Q{}local-name (or local-name}), and for one in a namespace it’s Qhttp://example.org/nslocal-name+
27 28 29 30 |
# File 'lib/saxon/qname.rb', line 27 def self.eqname(eqname_string) s9_qname = Saxon::S9API::QName.fromEQName(eqname_string) new(s9_qname) end |
.resolve(qname_or_string, namespaces = {}) ⇒ Saxon::QName
Resolve a QName string into a Saxon::QName.
If the arg is a Saxon::QName already, it just gets returned. If it’s an instance of the underlying Saxon Java QName, it’ll be wrapped into a Saxon::QName
If the arg is a string, it’s resolved by using resolve_qname_string
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/saxon/qname.rb', line 63 def self.resolve(qname_or_string, namespaces = {}) case qname_or_string when String, Symbol resolve_qname_string(qname_or_string, namespaces) when self qname_or_string when Saxon::S9API::QName new(qname_or_string) end end |
.resolve_qname_string(qname_string, namespaces = {}) ⇒ Saxon::QName
Resolve a QName string of the form “prefix:local-name” into a Saxon::QName by looking up the namespace URI in a hash of "prefix" => "namespace-uri"
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/saxon/qname.rb', line 81 def self.resolve_qname_string(qname_string, namespaces = {}) local_name, prefix = qname_string.to_s.split(':').reverse uri = nil if prefix uri = namespaces[prefix] raise self::PrefixedStringWithoutNSURIError.new(qname_string, prefix) if uri.nil? end create(prefix: prefix, uri: uri, local_name: local_name) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare this QName with another. They compare equal if they have same URI and local name. Prefix is ignored.
141 142 143 144 |
# File 'lib/saxon/qname.rb', line 141 def ==(other) return false unless other.is_a?(QName) s9_qname.equals(other.to_java) end |
#clark ⇒ String
Return a Clark notation representation of the QName:
"{http://ns.url}local-name"
Note that the prefix is lost in Clark notation.
122 123 124 |
# File 'lib/saxon/qname.rb', line 122 def clark @s9_qname.getClarkName end |
#eqname ⇒ String
Return a Extended QName notation representation of the QName:
"Q{http://ns.url}local-name"
Note that the prefix is lost in EQName notation.
132 133 134 |
# File 'lib/saxon/qname.rb', line 132 def eqname @s9_qname.getEQName end |
#hash ⇒ Object
Compute a hash-code for this Saxon::QName.
Two QNamess with the same local name and URI will have the same hash code (and will compare using eql?).
151 152 153 |
# File 'lib/saxon/qname.rb', line 151 def hash @hash ||= (local_name + uri).hash end |
#inspect ⇒ Object
Returns a more detailed string representation of the object, showing prefix, uri, and local_name instance variables
171 172 173 |
# File 'lib/saxon/qname.rb', line 171 def inspect "<Saxon::QName @prefix=#{prefix} @uri=#{uri} @local_name=#{local_name}>" end |
#local_name ⇒ String
Returns The local name part of the QName.
102 103 104 |
# File 'lib/saxon/qname.rb', line 102 def local_name @s9_qname.getLocalName end |
#prefix ⇒ String
Returns The prefix part of the QName (” if unset).
107 108 109 |
# File 'lib/saxon/qname.rb', line 107 def prefix @s9_qname.getPrefix end |
#to_java ⇒ Saxon::S9API::QName
Returns the underlying Saxon QName object.
156 157 158 |
# File 'lib/saxon/qname.rb', line 156 def to_java s9_qname end |
#to_s ⇒ Object
convert the QName to a lexical string, using the prefix (if there is one). So, Saxon::QName.clark('{http://example.org/#ns}hello').to_s
returns 'hello'
, and Saxon::QName.create(prefix: 'pre', uri: 'http://example.org/#ns', local_name: 'hello').to_s
returns 'pre:hello'
165 166 167 |
# File 'lib/saxon/qname.rb', line 165 def to_s s9_qname.to_s end |
#uri ⇒ String
Returns The namespace URI part of the QName (” if unset).
112 113 114 |
# File 'lib/saxon/qname.rb', line 112 def uri @s9_qname.getNamespaceURI end |