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) ⇒ Object
- .create(opts = {}) ⇒ Object
- .eqname(eqname_string) ⇒ Object
-
.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) ⇒ Object (also: #eql?)
-
#clark ⇒ String
Return a Clark notation representation of the QName:.
-
#eqname ⇒ String
Return a Extended QName notation representation of the QName:.
- #hash ⇒ Object
-
#initialize(s9_qname) ⇒ QName
constructor
private
A new instance of QName.
- #inspect ⇒ Object
-
#local_name ⇒ String
The local name part of the QName.
-
#prefix ⇒ String
The prefix part of the QName (” if unset).
- #to_java ⇒ Object
- #to_s ⇒ Object
-
#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.
74 75 76 |
# File 'lib/saxon/qname.rb', line 74 def initialize(s9_qname) @s9_qname = s9_qname end |
Class Method Details
.clark(clark_string) ⇒ Object
6 7 8 9 |
# File 'lib/saxon/qname.rb', line 6 def self.clark(clark_string) s9_qname = Saxon::S9API::QName.fromClarkName(clark_string) new(s9_qname) end |
.create(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/saxon/qname.rb', line 16 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) ⇒ Object
11 12 13 14 |
# File 'lib/saxon/qname.rb', line 11 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_variable_name
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/saxon/qname.rb', line 40 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"
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/saxon/qname.rb', line 58 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) ⇒ Object Also known as: eql?
113 114 115 116 |
# File 'lib/saxon/qname.rb', line 113 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.
99 100 101 |
# File 'lib/saxon/qname.rb', line 99 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.
109 110 111 |
# File 'lib/saxon/qname.rb', line 109 def eqname @s9_qname.getEQName end |
#hash ⇒ Object
119 120 121 |
# File 'lib/saxon/qname.rb', line 119 def hash @hash ||= (local_name + uri).hash end |
#inspect ⇒ Object
131 132 133 |
# File 'lib/saxon/qname.rb', line 131 def inspect "<Saxon::QName @prefix=#{prefix} @uri=#{uri} @local_name=#{local_name}>" end |
#local_name ⇒ String
Returns The local name part of the QName.
79 80 81 |
# File 'lib/saxon/qname.rb', line 79 def local_name @s9_qname.getLocalName end |
#prefix ⇒ String
Returns The prefix part of the QName (” if unset).
84 85 86 |
# File 'lib/saxon/qname.rb', line 84 def prefix @s9_qname.getPrefix end |
#to_java ⇒ Object
123 124 125 |
# File 'lib/saxon/qname.rb', line 123 def to_java s9_qname end |
#to_s ⇒ Object
127 128 129 |
# File 'lib/saxon/qname.rb', line 127 def to_s s9_qname.to_s end |
#uri ⇒ String
Returns The namespace URI part of the QName (” if unset).
89 90 91 |
# File 'lib/saxon/qname.rb', line 89 def uri @s9_qname.getNamespaceURI end |