Class: Saxon::XDM::Array
- Inherits:
-
Object
- Object
- Saxon::XDM::Array
- Includes:
- Enumerable, ItemSequenceLike, SequenceLike
- Defined in:
- lib/saxon/xdm/array.rb
Overview
Represents an XDM Array
Class Method Summary collapse
-
.create(array) ⇒ XDM::Array
Create a new Array from a Ruby Array.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
compares two AtomicValues using the underlying Saxon and XDM comparision rules.
-
#[](i) ⇒ Object
Fetch element at index
i
in the array. -
#each {|value| ... } ⇒ Object
Iterate over the Array, yielding each element.
-
#hash ⇒ Object
Compute a hash-code for this Array.
-
#initialize(s9_xdm_array) ⇒ Array
constructor
private
A new instance of Array.
-
#length ⇒ Integer
(also: #size)
The length of the array.
-
#to_a ⇒ Object
Return a (frozen) Ruby Array containing all the elements of the Array.
-
#to_java ⇒ Object
The underlying Java XdmArray.
Methods included from ItemSequenceLike
#sequence_enum, #sequence_size
Methods included from SequenceLike
#append, #sequence_enum, #sequence_size
Constructor Details
#initialize(s9_xdm_array) ⇒ Array
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 Array.
32 33 34 |
# File 'lib/saxon/xdm/array.rb', line 32 def initialize(s9_xdm_array) @s9_xdm_array = s9_xdm_array end |
Class Method Details
.create(array) ⇒ XDM::Array
Create a new Saxon::XDM::Array from a Ruby Array. The contents of the array will be converted to Values using XDM.Value(). An existing S9API::XdmArray will simply be wrapped and returned.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/saxon/xdm/array.rb', line 13 def self.create(array) case array when S9API::XdmArray new(array) else new(S9API::XdmArray.new(array.map { |item| XDM.Value(item).to_java })) end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
compares two Saxon::XDM::AtomicValues using the underlying Saxon and XDM comparision rules
60 61 62 63 64 |
# File 'lib/saxon/xdm/array.rb', line 60 def ==(other) return false unless other.is_a?(XDM::Array) return false if length != other.length cached_array == other.to_a end |
#[](i) ⇒ Object
Fetch element at index i
in the array.
44 45 46 |
# File 'lib/saxon/xdm/array.rb', line 44 def [](i) cached_array[i] end |
#each {|value| ... } ⇒ Object
Iterate over the Array, yielding each element.
38 39 40 |
# File 'lib/saxon/xdm/array.rb', line 38 def each(&block) cached_array.each(&block) end |
#hash ⇒ Object
Compute a hash-code for this Saxon::XDM::Array.
Two Saxon::XDM::Arrays with the same content will have the same hash code (and will compare using eql?).
77 78 79 |
# File 'lib/saxon/xdm/array.rb', line 77 def hash @hash ||= cached_array.hash end |
#length ⇒ Integer Also known as: size
Returns the length of the array.
49 50 51 |
# File 'lib/saxon/xdm/array.rb', line 49 def length s9_xdm_array.arrayLength end |
#to_a ⇒ Object
Return a (frozen) Ruby Array containing all the elements of the Saxon::XDM::Array
67 68 69 |
# File 'lib/saxon/xdm/array.rb', line 67 def to_a cached_array end |
#to_java ⇒ Object
Returns the underlying Java XdmArray.
82 83 84 |
# File 'lib/saxon/xdm/array.rb', line 82 def to_java s9_xdm_array end |