Class: Saxon::XDM::Value
- Inherits:
-
Object
- Object
- Saxon::XDM::Value
- Includes:
- Enumerable, SequenceLike
- Defined in:
- lib/saxon/xdm/value.rb
Overview
An XPath Data Model Value object, representing a Sequence.
Class Method Summary collapse
-
.create(*items) ⇒ Saxon::XDM::Value
Create a new XDM::Value sequence containing the items passed in as a Ruby enumerable.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare this XDM::Value with another.
-
# {|item| ... } ⇒ Object
Calls the given block once for each Item in the sequence, passing that item as a parameter.
-
#hash ⇒ Fixnum
The hash code for the XDM::Value.
-
#initialize(s9_xdm_value) ⇒ Value
constructor
private
A new instance of Value.
-
#sequence_enum ⇒ Object
Returns an enumerator over the Sequence.
-
#sequence_size ⇒ Integer
The size of the sequence.
-
#size ⇒ Fixnum
The size of the sequence.
-
#to_enum ⇒ Enumerator::Lazy
(also: #enum_for)
Returns a lazy Enumerator over the sequence.
-
#to_java ⇒ Saxon::S9API::XdmValue
The underlying Saxon Java XDM valuee object.
Methods included from SequenceLike
Constructor Details
#initialize(s9_xdm_value) ⇒ Value
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 Value.
79 80 81 |
# File 'lib/saxon/xdm/value.rb', line 79 def initialize(s9_xdm_value) @s9_xdm_value = s9_xdm_value end |
Class Method Details
.create(*items) ⇒ Saxon::XDM::Value
Create a new XDM::Value sequence containing the items passed in as a Ruby enumerable.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/saxon/xdm/value.rb', line 16 def create(*items) items = items.flatten case items.size when 0 XDM.EmptySequence() when 1 if value = maybe_xdm_value(items.first) return value end XDM.Item(items.first) else new(Saxon::S9API::XdmValue.new(wrap_items(items))) end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare this XDM::Value with another. Currently this requires iterating across the sequence, and the other sequence and comparing each member with the corresponding member in the other sequence.
111 112 113 114 115 116 117 118 |
# File 'lib/saxon/xdm/value.rb', line 111 def ==(other) return false unless other.is_a?(XDM::Value) return false unless other.size == size not_okay = to_enum.zip(other.to_enum).find { |mine, theirs| mine != theirs } not_okay.nil? || !not_okay end |
# {|item| ... } ⇒ Object
Calls the given block once for each Item in the sequence, passing that item as a parameter. Returns the value itself.
If no block is given, an Enumerator is returned.
96 97 98 |
# File 'lib/saxon/xdm/value.rb', line 96 def each(&block) to_enum.each(&block) end |
#hash ⇒ Fixnum
The hash code for the XDM::Value
124 125 126 |
# File 'lib/saxon/xdm/value.rb', line 124 def hash @hash ||= to_a.hash end |
#sequence_enum ⇒ Object
Returns an enumerator over the Sequence
139 140 141 |
# File 'lib/saxon/xdm/value.rb', line 139 def sequence_enum to_enum end |
#sequence_size ⇒ Integer
Returns the size of the sequence.
144 145 146 |
# File 'lib/saxon/xdm/value.rb', line 144 def sequence_size s9_xdm_value.size end |
#size ⇒ Fixnum
Returns The size of the sequence.
84 85 86 |
# File 'lib/saxon/xdm/value.rb', line 84 def size s9_xdm_value.size end |
#to_enum ⇒ Enumerator::Lazy Also known as: enum_for
Returns a lazy Enumerator over the sequence
130 131 132 133 134 |
# File 'lib/saxon/xdm/value.rb', line 130 def to_enum s9_xdm_value.enum_for(:each).lazy.map { |s9_xdm_item| XDM.Item(s9_xdm_item) }.each end |
#to_java ⇒ Saxon::S9API::XdmValue
Returns The underlying Saxon Java XDM valuee object.
101 102 103 |
# File 'lib/saxon/xdm/value.rb', line 101 def to_java @s9_xdm_value end |