Class: Saxon::ItemType::LexicalStringConversion::FloatConversion

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

Overview

Helper class for performing conversion and validation to XDM Floating-point types from Ruby’s Float class

Instance Method Summary collapse

Constructor Details

#initialize(size = :double) ⇒ FloatConversion

Returns a new instance of FloatConversion.



84
85
86
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 84

def initialize(size = :double)
  @double = size == :double
end

Instance Method Details

#call(value, item_type) ⇒ String

Check a value against our type constraints, and return the lexical string representation if it’s okay.

Parameters:

  • value (Float)

    the ruby value

  • item_type (Saxon::ItemType)

    the item type

Returns:

  • (String)

    the lexical string representation of the value



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 94

def call(value, item_type)
  case value
  when ::Float::INFINITY
    'INF'
  when -::Float::INFINITY
    '-INF'
  when Numeric
    float_value(value).to_s
  else
    LexicalStringConversion.validate(value, item_type, Patterns::FLOAT)
  end
end