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
Constant Summary collapse
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.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
compares two AtomicValues using the underlying Saxon and XDM comparision rules.
- #hash ⇒ Object
-
#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.
117 118 119 |
# File 'lib/saxon/xdm/atomic_value.rb', line 117 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/saxon/xdm/atomic_value.rb', line 59 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.
88 89 90 91 92 |
# File 'lib/saxon/xdm/atomic_value.rb', line 88 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
161 162 163 164 |
# File 'lib/saxon/xdm/atomic_value.rb', line 161 def ==(other) return false unless other.is_a?(XDM::AtomicValue) s9_xdm_atomic_value.equals(other.to_java) end |
#hash ⇒ Object
168 169 170 |
# File 'lib/saxon/xdm/atomic_value.rb', line 168 def hash @hash ||= s9_xdm_atomic_value.hashCode end |
#item_type ⇒ Saxon::ItemType
Returns The ItemType of the value.
143 144 145 |
# File 'lib/saxon/xdm/atomic_value.rb', line 143 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.
130 131 132 |
# File 'lib/saxon/xdm/atomic_value.rb', line 130 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
152 153 154 |
# File 'lib/saxon/xdm/atomic_value.rb', line 152 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.
138 139 140 |
# File 'lib/saxon/xdm/atomic_value.rb', line 138 def to_s s9_xdm_atomic_value.toString end |
#type_name ⇒ Saxon::QName
Return a QName representing the type of the value
124 125 126 |
# File 'lib/saxon/xdm/atomic_value.rb', line 124 def type_name @type_name ||= Saxon::QName.new(s9_xdm_atomic_value.getTypeName) end |