Class: Saxon::ItemType::LexicalStringConversion::IntegerConversion
- Inherits:
-
Object
- Object
- Saxon::ItemType::LexicalStringConversion::IntegerConversion
- Defined in:
- lib/saxon/item_type/lexical_string_conversion.rb
Overview
Helper class for performing conversion and validation to XDM integer types from Ruby’s Fixnum/Bignum/Integer classes
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
-
#call(value, item_type) ⇒ String
Check a value against our type constraints, and return the lexical string representation if it’s okay.
-
#gte_min?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is >= the lower bound of the range allowed for the XDM type.
-
#in_bounds?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is within the range allowed for the XDM type.
-
#initialize(min, max) ⇒ IntegerConversion
constructor
A new instance of IntegerConversion.
-
#lte_max?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is <= the upper bound of the range allowed for the XDM type.
Constructor Details
#initialize(min, max) ⇒ IntegerConversion
Returns a new instance of IntegerConversion.
31 32 33 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 31 def initialize(min, max) @min, @max = min, max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
29 30 31 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 29 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
29 30 31 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 29 def min @min 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.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 69 def call(value, item_type) integer_value = case value when ::Numeric value.to_i else Integer(LexicalStringConversion.validate(value, item_type, Patterns::INTEGER), 10) end raise Errors::RubyValueOutOfBounds.new(value, item_type) unless in_bounds?(integer_value) integer_value.to_s end |
#gte_min?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is >= the lower bound of the range allowed for the XDM type
47 48 49 50 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 47 def gte_min?(integer_value) return true if min.nil? integer_value >= min end |
#in_bounds?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is within the range allowed for the XDM type
39 40 41 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 39 def in_bounds?(integer_value) gte_min?(integer_value) && lte_max?(integer_value) end |
#lte_max?(integer_value) ⇒ Boolean
Returns whether the Ruby integer is <= the upper bound of the range allowed for the XDM type
56 57 58 59 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 56 def lte_max?(integer_value) return true if max.nil? integer_value <= max end |