Class: Saxon::XDM::Array

Inherits:
Object
  • Object
show all
Includes:
Enumerable, ItemSequenceLike, SequenceLike
Defined in:
lib/saxon/xdm/array.rb

Overview

Represents an XDM Array

Class Method Summary collapse

Instance Method Summary collapse

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.

Returns:



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

Parameters:

Returns:

  • (Boolean)


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.

Parameters:

  • i (Integer)

    the index of the element to retrieve.



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.

Yield Parameters:

  • value (XDM::Value)

    the current value from the Array



38
39
40
# File 'lib/saxon/xdm/array.rb', line 38

def each(&block)
  cached_array.each(&block)
end

#hashObject

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?).

See Also:

  • Object#hash


77
78
79
# File 'lib/saxon/xdm/array.rb', line 77

def hash
  @hash ||= cached_array.hash
end

#lengthInteger Also known as: size

Returns the length of the array.

Returns:

  • (Integer)

    the length of the array



49
50
51
# File 'lib/saxon/xdm/array.rb', line 49

def length
  s9_xdm_array.arrayLength
end

#to_aObject

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_javaObject

Returns the underlying Java XdmArray.

Returns:

  • the underlying Java XdmArray



82
83
84
# File 'lib/saxon/xdm/array.rb', line 82

def to_java
  s9_xdm_array
end