Class: Saxon::XDM::Value

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

Overview

An XPath Data Model Value object, representing a Sequence.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SequenceLike

#append

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.

Parameters:

  • items (Enumerable)

    A list of members

Returns:



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.

Parameters:

Returns:

  • (Boolean)

    whether the two XDM::Values are equal



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.

Yields:

  • (item)

    The current XDM Item

Yield Parameters:



96
97
98
# File 'lib/saxon/xdm/value.rb', line 96

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

#hashFixnum

The hash code for the XDM::Value

Returns:

  • (Fixnum)

    The hash code



124
125
126
# File 'lib/saxon/xdm/value.rb', line 124

def hash
  @hash ||= to_a.hash
end

#sequence_enumObject

Returns an enumerator over the Sequence



139
140
141
# File 'lib/saxon/xdm/value.rb', line 139

def sequence_enum
  to_enum
end

#sequence_sizeInteger

Returns the size of the sequence.

Returns:

  • (Integer)

    the size of the sequence



144
145
146
# File 'lib/saxon/xdm/value.rb', line 144

def sequence_size
  s9_xdm_value.size
end

#sizeFixnum

Returns The size of the sequence.

Returns:

  • (Fixnum)

    The size of the sequence



84
85
86
# File 'lib/saxon/xdm/value.rb', line 84

def size
  s9_xdm_value.size
end

#to_enumEnumerator::Lazy Also known as: enum_for

Returns a lazy Enumerator over the sequence

Returns:

  • (Enumerator::Lazy)

    the enumerator



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_javaSaxon::S9API::XdmValue

Returns The underlying Saxon Java XDM valuee object.

Returns:

  • (Saxon::S9API::XdmValue)

    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