Module: Saxon::ItemType::LexicalStringConversion::Convertors
- Defined in:
- lib/saxon/item_type/lexical_string_conversion.rb
Overview
Convertors from Ruby values to lexical string representations for a particular XDM type
Constant Summary collapse
- ANY_URI =
->(value, item_type) { uri_classes = [URI::Generic] case value when URI::Generic value.to_s else begin URI(value.to_s).to_s rescue URI::InvalidURIError raise Errors::BadRubyValue.new(value, item_type) end end }
- BASE64_BINARY =
->(value, item_type) { Base64.strict_encode64(value.to_s.force_encoding(Encoding::ASCII_8BIT)) }
- BOOLEAN =
->(value, item_type) { value ? 'true' : 'false' }
- BYTE =
ByteConversion.new
- DATE =
->(value, item_type) { if value.respond_to?(:strftime) value.strftime('%F') else LexicalStringConversion.validate(value, item_type, Patterns::DATE) end }
- DATE_TIME =
->(value, item_type) { if value.respond_to?(:strftime) value.strftime('%FT%T%:z') else LexicalStringConversion.validate(value, item_type, Patterns::DATE_TIME) end }
- TIME =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::TIME) }
- DATE_TIME_STAMP =
DATE_TIME
- DAY_TIME_DURATION =
DurationConversion.new(Patterns::DAY_TIME_DURATION)
- DECIMAL =
->(value, item_type) { case value when ::Integer value.to_s when ::BigDecimal value.to_s('F') when ::Float BigDecimal(value, ::Float::DIG).to_s('F') else LexicalStringConversion.validate(value, item_type, Patterns::DECIMAL) end }
- DOUBLE =
FloatConversion.new(:single)
- DURATION =
DurationConversion.new(Patterns::DURATION)
- FLOAT =
FloatConversion.new
- G_DAY =
GDateConversion.new({ bounds: 1..31, validation_pattern: Patterns::G_DAY, integer_formatter: ->(value) { '---%02d' } })
- G_MONTH =
GDateConversion.new({ bounds: 1..12, validation_pattern: Patterns::G_MONTH, integer_formatter: ->(value) { '--%02d' } })
- G_MONTH_DAY =
->(value, item_type) { month_days = { 1 => 31, 2 => 29, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 } formatted_value = LexicalStringConversion.validate(value, item_type, Patterns::G_MONTH_DAY) month, day = Patterns::G_MONTH_DAY.match(formatted_value).captures.take(2).map { |i| Integer(i, 10) } raise Errors::RubyValueOutOfBounds.new(value, item_type) if day > month_days[month] formatted_value }
- G_YEAR =
GDateConversion.new({ bounds: ->(value) { value != 0 }, validation_pattern: Patterns::G_YEAR, integer_formatter: ->(value) { value.negative? ? '%05d' : '%04d' } })
- G_YEAR_MONTH =
->(value, item_type) { formatted_value = LexicalStringConversion.validate(value, item_type, Patterns::G_YEAR_MONTH) year, month = Patterns::G_YEAR_MONTH.match(formatted_value).captures.take(2).map { |i| Integer(i, 10) } if year == 0 || !(1..12).include?(month) raise Errors::RubyValueOutOfBounds.new(value, item_type) end value }
- HEX_BINARY =
->(value, item_type) { value.to_s.force_encoding(Encoding::ASCII_8BIT).each_byte.map { |b| b.to_s(16) }.join }
- INT =
IntegerConversion.new(-2147483648, 2147483647)
- INTEGER =
IntegerConversion.new(nil, nil)
- LANGUAGE =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::LANGUAGE) }
- LONG =
IntegerConversion.new(-9223372036854775808, 9223372036854775807)
- NAME =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::NAME) }
- ID =
IDREF = ENTITY = NCNAME = ->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::NCNAME) }
- NEGATIVE_INTEGER =
IntegerConversion.new(nil, -1)
- NMTOKEN =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::NMTOKEN) }
- NON_NEGATIVE_INTEGER =
IntegerConversion.new(0, nil)
- NON_POSITIVE_INTEGER =
IntegerConversion.new(nil, 0)
- NORMALIZED_STRING =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::NORMALIZED_STRING) }
- POSITIVE_INTEGER =
IntegerConversion.new(1, nil)
- SHORT =
IntegerConversion.new(-32768, 32767)
- TOKEN =
STRING (It’s questionable whether anything needs doing here)
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::TOKEN) }
- UNSIGNED_BYTE =
ByteConversion.new(:unsigned)
- UNSIGNED_INT =
IntegerConversion.new(0, 4294967295)
- UNSIGNED_LONG =
IntegerConversion.new(0, 18446744073709551615)
- UNSIGNED_SHORT =
IntegerConversion.new(0, 65535)
- YEAR_MONTH_DURATION =
->(value, item_type) { LexicalStringConversion.validate(value, item_type, Patterns::YEAR_MONTH_DURATION) }
- QNAME =
NOTATION = ->(value, item_type) { raise Errors::UnconvertableNamespaceSensitveItemType }