Module: Saxon::OccurrenceIndicator
- Defined in:
- lib/saxon/occurrence_indicator.rb
Overview
Provides simple access to Saxon’s OccurrenceIndicator constants, for declaring restrictions on the cardinality (length) of a sequence when, for example, defining a variable’s type
Class Method Summary collapse
-
.get_indicator(indicator_name) ⇒ Saxon::S9API::OccurrenceIndicator
Return an OccurrenceIndicator given a name as a symbol.
-
.indicator_names ⇒ Array<Symbol>
The list of valid occurence indicator names, as symbols.
-
.one ⇒ Object
One thing.
-
.one_or_more ⇒ Object
One or more things.
-
.zero ⇒ Object
no things (the empty sequence).
-
.zero_or_more ⇒ Object
zero or more things.
-
.zero_or_one ⇒ Object
an optional thing.
Class Method Details
.get_indicator(indicator_name) ⇒ Saxon::S9API::OccurrenceIndicator
Return an OccurrenceIndicator given a name as a symbol. Passes through existing OccurrenceIndicator instances: this method is primarily for API use, most people will find it easier to directly call one of the methods, as in OccurrenceIndicator.one
rather than OccurrenceIndicator.get_indicator(:one).
53 54 55 56 57 58 59 |
# File 'lib/saxon/occurrence_indicator.rb', line 53 def get_indicator(indicator_name) return indicator_name if indicator_name.is_a?(Saxon::S9API::OccurrenceIndicator) unless indicator_names.include?(indicator_name) raise ArgumentError, "#{indicator_name.inspect} is not a valid indicator name (one of #{indicator_names.map(&:inspect).join(', ')})" end OccurrenceIndicator.send(indicator_name) end |
.indicator_names ⇒ Array<Symbol>
The list of valid occurence indicator names, as symbols. These correspond directly to the methods returning OccurrenceIndicators in this module.
39 40 41 42 43 |
# File 'lib/saxon/occurrence_indicator.rb', line 39 def indicator_names # .refine gets added to modules that have methods, so it's not in # Module's public_methods list @indicator_names ||= (public_methods(false) - Module.public_methods - [:indicator_names, :get_indicator, :refine]) end |
.one ⇒ Object
One thing
10 11 12 |
# File 'lib/saxon/occurrence_indicator.rb', line 10 def one @one ||= Saxon::S9API::OccurrenceIndicator::ONE end |
.one_or_more ⇒ Object
One or more things
15 16 17 |
# File 'lib/saxon/occurrence_indicator.rb', line 15 def one_or_more @one_or_more ||= Saxon::S9API::OccurrenceIndicator::ONE_OR_MORE end |
.zero ⇒ Object
no things (the empty sequence)
20 21 22 |
# File 'lib/saxon/occurrence_indicator.rb', line 20 def zero @zero ||= Saxon::S9API::OccurrenceIndicator::ZERO end |