Module: Saxon::ItemType::LexicalStringConversion

Defined in:
lib/saxon/item_type/lexical_string_conversion.rb

Overview

A collection of lamba-like objects for converting Ruby values into lexical strings for specific XSD datatypes

Defined Under Namespace

Modules: Convertors, Errors, PatternFragments, Patterns Classes: ByteConversion, DurationConversion, FloatConversion, GDateConversion, IntegerConversion

Class Method Summary collapse

Class Method Details

.validate(value, item_type, pattern) ⇒ String

Simple validation helper that checks if a value string matches an allowed lexical string pattern space or not.

Parameters:

  • value (Object)

    the value whose to_s representation should be checked

  • item_type (Saxon::ItemType)

    the ItemType whose lexical pattern space should be checked against

  • pattern (Regexp)

    the lexical pattern space Regexp to use in the checking

Returns:

  • (String)

    the lexical string for the value and type

Raises:

  • (Errors::BadRubyValue)

    if the ruby value doesn’t produce a string which validates against the allowed pattern



20
21
22
23
24
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 20

def self.validate(value, item_type, pattern)
  str = value.to_s
  raise Errors::BadRubyValue.new(value, item_type) if str.match(pattern).nil?
  str
end