Class: Saxon::XdmValue

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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

Constructor Details

#initialize(s9_xdm_value) ⇒ XdmValue

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 XdmValue.



44
45
46
# File 'lib/saxon/xdm_value.rb', line 44

def initialize(s9_xdm_value)
  @s9_xdm_value = s9_xdm_value
end

Class Method Details

.create(items) ⇒ Saxon::XdmValue

Create a new XdmValue sequence containing the items passed in as a Ruby enumerable.

Parameters:

  • items (Enumerable)

    A list of XDM Item members

Returns:



36
37
38
# File 'lib/saxon/xdm_value.rb', line 36

def self.create(items)
  new(Saxon::S9API::XdmValue.makeSequence(items.map(&:to_java)))
end

.wrap_s9_xdm_item(s9_xdm_item) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/saxon/xdm_value.rb', line 19

def self.wrap_s9_xdm_item(s9_xdm_item)
  if s9_xdm_item.isAtomicValue
    XdmAtomicValue.new(s9_xdm_item)
  else
    case s9_xdm_item
    when Saxon::S9API::XdmNode
      XdmNode.new(s9_xdm_item)
    else
      XdmUnhandledItem.new(s9_xdm_item)
    end
  end
end

.wrap_s9_xdm_value(s9_xdm_value) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/saxon/xdm_value.rb', line 9

def self.wrap_s9_xdm_value(s9_xdm_value)
  return new(s9_xdm_value) if s9_xdm_value.instance_of?(Saxon::S9API::XdmValue)
  case s9_xdm_value
  when Saxon::S9API::XdmEmptySequence
    new([])
  else
    wrap_s9_xdm_item(s9_xdm_value)
  end
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compare this XdmValue 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 XdmValues are equal



76
77
78
79
80
81
82
83
# File 'lib/saxon/xdm_value.rb', line 76

def ==(other)
  return false unless other.is_a?(XdmValue)
  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:



61
62
63
# File 'lib/saxon/xdm_value.rb', line 61

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

#hashFixnum

The hash code for the XdmValue

Returns:

  • (Fixnum)

    The hash code



89
90
91
# File 'lib/saxon/xdm_value.rb', line 89

def hash
  @hash ||= to_a.hash
end

#sizeFixnum

Returns The size of the sequence.

Returns:

  • (Fixnum)

    The size of the sequence



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

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



95
96
97
98
99
# File 'lib/saxon/xdm_value.rb', line 95

def to_enum
  s9_xdm_value.each.lazy.map { |s9_xdm_item|
    wrap_s9_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.



66
67
68
# File 'lib/saxon/xdm_value.rb', line 66

def to_java
  @s9_xdm_value
end