Class: Saxon::ItemType::LexicalStringConversion::GDateConversion

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/item_type/lexical_string_conversion.rb

Overview

Helper class for creating convertors for the various G* Date-related types that allow single values (GDay, GMonth, GYear).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ GDateConversion

Returns a new instance of GDateConversion.

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :bounds (Range)

    the integer bounds for values of this type

  • :validation_pattern (Regexp)

    the pattern used to validate the value when it’s a String not an Integer

  • :integer_formatter (Proc)

    a proc/lambda that will produce a correctly-formatted lexical string from an Integer value



168
169
170
171
172
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 168

def initialize(args = {})
  @bounds = args.fetch(:bounds)
  @validation_pattern = args.fetch(:validation_pattern)
  @integer_formatter = args.fetch(:integer_formatter)
end

Instance Attribute Details

#boundsObject (readonly)

Returns the value of attribute bounds.



160
161
162
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160

def bounds
  @bounds
end

#integer_formatterObject (readonly)

Returns the value of attribute integer_formatter.



160
161
162
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160

def integer_formatter
  @integer_formatter
end

#validation_patternObject (readonly)

Returns the value of attribute validation_pattern.



160
161
162
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160

def validation_pattern
  @validation_pattern
end

Instance Method Details

#call(value, item_type) ⇒ String

Returns a correctly formatted String.

Parameters:

  • value (String, Integer)

    the value to convert

  • item_type (XDM::ItemType)

    the type being converted to

Returns:

  • (String)

    a correctly formatted String



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 177

def call(value, item_type)
  case value
  when Integer
    check_value_bounds!(value, item_type)
    sprintf(integer_formatter.call(value), value)
  else
    formatted_value = LexicalStringConversion.validate(value, item_type, validation_pattern)
    extract_and_check_value_bounds!(formatted_value, item_type)
    formatted_value
  end
end