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

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

Parameters:

  • indicator_name (Symbol, Saxon::S9API::OccurrenceIndicator)

    the name of the OccurrenceIndicator to return

Returns:

  • (Saxon::S9API::OccurrenceIndicator)

    the OccurrenceIndicator



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_namesArray<Symbol>

The list of valid occurence indicator names, as symbols. These correspond directly to the methods returning OccurrenceIndicators in this module.

Returns:

  • (Array<Symbol>)

    the indicator names



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

.oneObject

One thing



10
11
12
# File 'lib/saxon/occurrence_indicator.rb', line 10

def one
  @one ||= Saxon::S9API::OccurrenceIndicator::ONE
end

.one_or_moreObject

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

.zeroObject

no things (the empty sequence)



20
21
22
# File 'lib/saxon/occurrence_indicator.rb', line 20

def zero
  @zero ||= Saxon::S9API::OccurrenceIndicator::ZERO
end

.zero_or_moreObject

zero or more things



25
26
27
# File 'lib/saxon/occurrence_indicator.rb', line 25

def zero_or_more
  @zero_or_more ||= Saxon::S9API::OccurrenceIndicator::ZERO_OR_MORE
end

.zero_or_oneObject

an optional thing



30
31
32
# File 'lib/saxon/occurrence_indicator.rb', line 30

def zero_or_one
  @zero_or_one ||= Saxon::S9API::OccurrenceIndicator::ZERO_OR_ONE
end