Class: Saxon::XDM::AtomicValue
- Inherits:
-
Object
- Object
- Saxon::XDM::AtomicValue
- Includes:
- ItemSequenceLike, SequenceLike
- Defined in:
- lib/saxon/xdm/atomic_value.rb
Overview
An XPath Data Model Node object, representing an XML document, or an element or one of the other node chunks in the XDM.
Defined Under Namespace
Classes: CannotCreateQNameFromString, NotationCannotBeDirectlyCreated
Class Method Summary collapse
-
.create(value, item_type = nil) ⇒ Saxon::XDM::AtomicValue
Convert a single Ruby value into an XDM::AtomicValue.
-
.from_lexical_string(value, item_type) ⇒ Saxon::XDM::AtomicValue
convert a lexical string representation of an XDM Atomic Value into an XDM::AtomicValue.
-
.xs_notation ⇒ Object
ItemType representing NOTATION.
-
.xs_qname ⇒ Object
ItemType representing QNames.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
compares two AtomicValues using the underlying Saxon and XDM comparision rules.
-
#hash ⇒ Object
Compute a hash-code for this AtomicValue.
-
#initialize(s9_xdm_atomic_value) ⇒ AtomicValue
constructor
private
A new instance of AtomicValue.
-
#item_type ⇒ Saxon::ItemType
The ItemType of the value.
-
#to_java ⇒ Saxon::S9API::XdmAtomicValue
atomic value object.
-
#to_ruby ⇒ Object
Return the value as an instance of the Ruby class that best represents the type of the value.
-
#to_s ⇒ String
Return the value as a String.
-
#type_name ⇒ Saxon::QName
Return a QName representing the type of the value.
Methods included from ItemSequenceLike
#sequence_enum, #sequence_size
Methods included from SequenceLike
#append, #sequence_enum, #sequence_size
Constructor Details
#initialize(s9_xdm_atomic_value) ⇒ AtomicValue
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 AtomicValue.
126 127 128 |
# File 'lib/saxon/xdm/atomic_value.rb', line 126 def initialize(s9_xdm_atomic_value) @s9_xdm_atomic_value = s9_xdm_atomic_value end |
Class Method Details
.create(value, item_type = nil) ⇒ Saxon::XDM::AtomicValue
Convert a single Ruby value into an XDM::AtomicValue
If no explicit ItemType is passed, the correct type is guessed based on the class of the value. (e.g. xs:date
for Date.)
Values are converted based on Ruby idioms and operations, so an explicit ItemType of xs:boolean
will use truthyness to evaluate the value. This means that the Ruby string 'false'
will produce an xs:boolean
whose value is true
, because all strings are truthy. If you need to pass lexical strings unchanged, use from_lexical_string.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/saxon/xdm/atomic_value.rb', line 68 def create(value, item_type = nil) case value when Saxon::S9API::XdmAtomicValue new(value) when XDM::AtomicValue value else return (value) if item_type.nil? item_type = ItemType.get_type(item_type) return new(Saxon::S9API::XdmAtomicValue.new(value.to_java)) if item_type == xs_qname && value_is_qname?(value) raise NotationCannotBeDirectlyCreated if item_type == xs_notation value_lexical_string = item_type.lexical_string(value) new(new_s9_xdm_atomic_value(value_lexical_string, item_type)) end end |
.from_lexical_string(value, item_type) ⇒ Saxon::XDM::AtomicValue
convert a lexical string representation of an XDM Atomic Value into an XDM::AtomicValue.
Note that this skips all conversion and checking of the string before handing it off to Saxon.
97 98 99 100 101 |
# File 'lib/saxon/xdm/atomic_value.rb', line 97 def from_lexical_string(value, item_type) item_type = ItemType.get_type(item_type) raise CannotCreateQNameFromString if item_type == xs_qname new(new_s9_xdm_atomic_value(value.to_s, item_type)) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
compares two Saxon::XDM::AtomicValues using the underlying Saxon and XDM comparision rules
170 171 172 173 |
# File 'lib/saxon/xdm/atomic_value.rb', line 170 def ==(other) return false unless other.is_a?(XDM::AtomicValue) s9_xdm_atomic_value.equals(other.to_java) end |
#hash ⇒ Object
Compute a hash-code for this Saxon::XDM::AtomicValue.
Two Saxon::XDM::AtomicValues with the same content will have the same hash code (and will compare using eql?).
181 182 183 |
# File 'lib/saxon/xdm/atomic_value.rb', line 181 def hash @hash ||= s9_xdm_atomic_value.hashCode end |
#item_type ⇒ Saxon::ItemType
Returns The ItemType of the value.
152 153 154 |
# File 'lib/saxon/xdm/atomic_value.rb', line 152 def item_type @item_type ||= Saxon::ItemType.get_type(Saxon::QName.resolve(s9_xdm_atomic_value.getTypeName)) end |
#to_java ⇒ Saxon::S9API::XdmAtomicValue
atomic value object.
139 140 141 |
# File 'lib/saxon/xdm/atomic_value.rb', line 139 def to_java s9_xdm_atomic_value end |
#to_ruby ⇒ Object
Return the value as an instance of the Ruby class that best represents the type of the value. Types with no sensible equivalent are returned as their lexical string form
161 162 163 |
# File 'lib/saxon/xdm/atomic_value.rb', line 161 def to_ruby @ruby_value ||= item_type.ruby_value(self).freeze end |
#to_s ⇒ String
Return the value as a String. Like calling XPath’s string()
function.
147 148 149 |
# File 'lib/saxon/xdm/atomic_value.rb', line 147 def to_s s9_xdm_atomic_value.toString end |
#type_name ⇒ Saxon::QName
Return a QName representing the type of the value
133 134 135 |
# File 'lib/saxon/xdm/atomic_value.rb', line 133 def type_name @type_name ||= Saxon::QName.new(s9_xdm_atomic_value.getTypeName) end |