Class: Saxon::ItemType::LexicalStringConversion::GDateConversion
- Inherits:
-
Object
- Object
- Saxon::ItemType::LexicalStringConversion::GDateConversion
- Defined in:
- lib/saxon/item_type/lexical_string_conversion.rb
Overview
Helper class for creating convertors for the various G* Date-related types that allow single values (GDay, GMonth, GYear).
Instance Attribute Summary collapse
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#integer_formatter ⇒ Object
readonly
Returns the value of attribute integer_formatter.
-
#validation_pattern ⇒ Object
readonly
Returns the value of attribute validation_pattern.
Instance Method Summary collapse
-
#call(value, item_type) ⇒ String
A correctly formatted String.
-
#initialize(args = {}) ⇒ GDateConversion
constructor
A new instance of GDateConversion.
Constructor Details
#initialize(args = {}) ⇒ GDateConversion
Returns a new instance of GDateConversion.
168 169 170 171 172 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 168 def initialize(args = {}) @bounds = args.fetch(:bounds) @validation_pattern = args.fetch(:validation_pattern) @integer_formatter = args.fetch(:integer_formatter) end |
Instance Attribute Details
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
160 161 162 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160 def bounds @bounds end |
#integer_formatter ⇒ Object (readonly)
Returns the value of attribute integer_formatter.
160 161 162 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160 def integer_formatter @integer_formatter end |
#validation_pattern ⇒ Object (readonly)
Returns the value of attribute validation_pattern.
160 161 162 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 160 def validation_pattern @validation_pattern end |
Instance Method Details
#call(value, item_type) ⇒ String
Returns a correctly formatted String.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 177 def call(value, item_type) case value when Integer check_value_bounds!(value, item_type) sprintf(integer_formatter.call(value), value) else formatted_value = LexicalStringConversion.validate(value, item_type, validation_pattern) extract_and_check_value_bounds!(formatted_value, item_type) formatted_value end end |