Class: Saxon::ItemType::LexicalStringConversion::IntegerConversion
- Inherits:
-
Object
- Object
- Saxon::ItemType::LexicalStringConversion::IntegerConversion
- Defined in:
- lib/saxon/item_type/lexical_string_conversion.rb
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) ⇒ Object
- #gte_min?(integer_value) ⇒ Boolean
- #in_bounds?(integer_value) ⇒ Boolean
-
#initialize(min, max) ⇒ IntegerConversion
constructor
A new instance of IntegerConversion.
- #lte_max?(integer_value) ⇒ Boolean
Constructor Details
#initialize(min, max) ⇒ IntegerConversion
Returns a new instance of IntegerConversion.
17 18 19 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 17 def initialize(min, max) @min, @max = min, max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
15 16 17 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 15 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
15 16 17 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 15 def min @min end |
Instance Method Details
#call(value, item_type) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 35 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
25 26 27 28 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 25 def gte_min?(integer_value) return true if min.nil? integer_value >= min end |
#in_bounds?(integer_value) ⇒ Boolean
21 22 23 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 21 def in_bounds?(integer_value) gte_min?(integer_value) && lte_max?(integer_value) end |
#lte_max?(integer_value) ⇒ Boolean
30 31 32 33 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 30 def lte_max?(integer_value) return true if max.nil? integer_value <= max end |