Class: Saxon::SequenceType
- Inherits:
-
Object
- Object
- Saxon::SequenceType
- Defined in:
- lib/saxon/sequence_type.rb
Overview
Represents a type definition for an XDM Sequence: an ItemType plus an OccurrenceIndicator as a restriction on the cardinality (length) of the sequence. Used most often to define variables in XPath or XSLT, plus in extension function definition.
Class Method Summary collapse
-
.create(type_name, occurrence_indicator = nil) ⇒ Saxon::SequenceType
Generate a SequenceType from a type declaration string (see SequenceType.from_type_decl), or some combination of type name/Ruby class (see ItemType.get_type), and an OccurrenceIndicator or symbol referencing an OccurenceIndicator (one of
:zero_or_more
,:one_or_more
,:zero_or_one
, or:one
). -
.from_type_decl(type_decl) ⇒ Saxon::SequenceType
Generate a SequenceType from a declaration string following the rules of parameter and function
as=
declarations in XSLT, like <tt><xsl:variable …
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare equal with another SequenceType.
-
#hash ⇒ Object
Generated hash code for use as keys in Hashes.
-
#initialize(item_type, occurrence_indicator = nil) ⇒ Saxon::SequenceType
constructor
The new SequenceType.
-
#item_type ⇒ Saxon::ItemType
The type’s ItemType.
-
#occurrence_indicator ⇒ net.sf.saxon.s9api.OccurrenceIndicator
The type’s OccurrenceIndicator.
-
#to_java ⇒ net.sf.saxon.s9api.SequenceType
The underlying Saxon SequenceType.
Constructor Details
#initialize(item_type, occurrence_indicator) ⇒ Saxon::SequenceType #initialize(s9_sequence_type) ⇒ Saxon::SequenceType
Returns the new SequenceType.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/saxon/sequence_type.rb', line 77 def initialize(item_type, occurrence_indicator = nil) if occurrence_indicator.nil? && !item_type.is_a?(S9API::SequenceType) raise ArgumentError, "Expected a Java s9api.SequenceType when handed a single argument, but got a #{item_type.class}" end if occurrence_indicator.nil? @s9_sequence_type = item_type else @item_type = item_type @occurrence_indicator = occurrence_indicator end end |
Class Method Details
.create(type_name, occurrence_indicator = nil) ⇒ Saxon::SequenceType
Generate a Saxon::SequenceType from a type declaration string (see from_type_decl), or some combination of type name/Ruby class (see ItemType.get_type), and an OccurrenceIndicator or symbol referencing an OccurenceIndicator (one of :zero_or_more
, :one_or_more
, :zero_or_one
, or :one
)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/saxon/sequence_type.rb', line 18 def create(type_name, occurrence_indicator = nil) case type_name when SequenceType return type_name when S9API::SequenceType return new(type_name) else check_for_complete_decl!(type_name, occurrence_indicator) return from_type_decl(type_name) if type_name.is_a?(String) && occurrence_indicator.nil? item_type = ItemType.get_type(type_name) occurrence_indicator = OccurrenceIndicator.get_indicator(occurrence_indicator) new(item_type, occurrence_indicator) end end |
.from_type_decl(type_decl) ⇒ Saxon::SequenceType
Generate a Saxon::SequenceType from a declaration string following the rules of parameter and function as=
declarations in XSLT, like <xsl:variable ... as="xs:string+"/>
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/saxon/sequence_type.rb', line 39 def from_type_decl(type_decl) occurence_char = type_decl[-1] occurence = case occurence_char when '?' new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.zero_or_one) when '+' new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.one_or_more) when '*' new(ItemType.get_type(type_decl[0..-2]), OccurrenceIndicator.zero_or_more) else new(ItemType.get_type(type_decl), OccurrenceIndicator.one) end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare equal with another SequenceType
108 109 110 111 |
# File 'lib/saxon/sequence_type.rb', line 108 def ==(other) return false if other.class != self.class item_type == other.item_type && occurrence_indicator == other.occurrence_indicator end |
#hash ⇒ Object
Generated hash code for use as keys in Hashes
115 116 117 |
# File 'lib/saxon/sequence_type.rb', line 115 def hash @hash ||= item_type.hash ^ occurrence_indicator.hash end |
#item_type ⇒ Saxon::ItemType
Returns the type’s ItemType.
91 92 93 |
# File 'lib/saxon/sequence_type.rb', line 91 def item_type @item_type ||= Saxon::ItemType.get_type(s9_sequence_type.getItemType) end |
#occurrence_indicator ⇒ net.sf.saxon.s9api.OccurrenceIndicator
Returns the type’s OccurrenceIndicator.
96 97 98 |
# File 'lib/saxon/sequence_type.rb', line 96 def occurrence_indicator @occurrence_indicator ||= s9_sequence_type.getOccurrenceIndicator end |
#to_java ⇒ net.sf.saxon.s9api.SequenceType
Returns the underlying Saxon SequenceType.
101 102 103 |
# File 'lib/saxon/sequence_type.rb', line 101 def to_java s9_sequence_type end |