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
- #sequence_size ⇒ Object
-
#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.
66 67 68 |
# File 'lib/saxon/xdm/value.rb', line 66 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 existing_value = maybe_xdm_value(items.first) return existing_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.
98 99 100 101 102 103 104 105 |
# File 'lib/saxon/xdm/value.rb', line 98 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.
83 84 85 |
# File 'lib/saxon/xdm/value.rb', line 83 def each(&block) to_enum.each(&block) end |
#hash ⇒ Fixnum
The hash code for the XDM::Value
111 112 113 |
# File 'lib/saxon/xdm/value.rb', line 111 def hash @hash ||= to_a.hash end |
#sequence_enum ⇒ Object
125 126 127 |
# File 'lib/saxon/xdm/value.rb', line 125 def sequence_enum to_enum end |
#sequence_size ⇒ Object
129 130 131 |
# File 'lib/saxon/xdm/value.rb', line 129 def sequence_size s9_xdm_value.size end |
#size ⇒ Fixnum
Returns The size of the sequence.
71 72 73 |
# File 'lib/saxon/xdm/value.rb', line 71 def size s9_xdm_value.size end |
#to_enum ⇒ Enumerator::Lazy Also known as: enum_for
Returns a lazy Enumerator over the sequence
117 118 119 120 121 |
# File 'lib/saxon/xdm/value.rb', line 117 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.
88 89 90 |
# File 'lib/saxon/xdm/value.rb', line 88 def to_java @s9_xdm_value end |