Class: Lutaml::Model::Type::String
- Defined in:
- lib/lutaml/model/type/string.rb
Direct Known Subclasses
Base64Binary, HexBinary, Uri, Xml::W3c::XlinkActuateType, Xml::W3c::XlinkArcroleType, Xml::W3c::XlinkHrefType, Xml::W3c::XlinkRoleType, Xml::W3c::XlinkShowType, Xml::W3c::XlinkTitleType, Xml::W3c::XlinkTypeAttrType, Xml::W3c::XmlBaseType, Xml::W3c::XmlIdType, Xml::W3c::XmlLangType, Xml::W3c::XmlSpaceType, Xml::W3c::XsiNil, Xml::W3c::XsiNoNamespaceSchemaLocationType, Xml::W3c::XsiSchemaLocationType, Xml::W3c::XsiType
Constant Summary
Constants inherited from Value
Value::EMPTY_OPTIONS, Value::LIST_FACETS, Value::MAX_FACETS, Value::MIN_FACETS, Value::WHITE_SPACE_MODES
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
-
.cast(value, options = {}) ⇒ Object
Performance-optimized cast with short-circuit for already-correct types.
-
.default_xsd_type ⇒ String
Default XSD type for String.
-
.white_space_mode ⇒ Object
Effective xs:whiteSpace mode for this type, defaulting to :preserve.
Methods inherited from Value
enumeration, exclusive, facets, format_type_serializer_for, fraction_digits, from_format, inclusive, inherited, #initialize, #initialized?, length, pattern, register_format_to_from_methods, register_format_type_serializer, serialize, tighter_facet, #to_s, total_digits, white_space
Methods included from Xml::Type::Configurable
Methods included from UninitializedClassGuard
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value, options = {}) ⇒ Object
Performance-optimized cast with short-circuit for already-correct types
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lutaml/model/type/string.rb', line 8 def self.cast(value, = {}) return nil if value.nil? return value if Utils.uninitialized?(value) # Short-circuit an already-::String value with no options only when # no xs:whiteSpace normalization is requested (the common :string # case); a non-preserve mode must fall through to transform the text. mode = white_space_mode if value.is_a?(::String) && .equal?(EMPTY_OPTIONS) && mode == :preserve return value end value = value.to_s value = value.gsub(/[\t\n\r]/, " ") unless mode == :preserve value = value.squeeze(" ").strip if mode == :collapse unless .equal?(EMPTY_OPTIONS) Model::Services::Type::Validator::String.validate!(value, ) end value end |
.default_xsd_type ⇒ String
Default XSD type for String
53 54 55 |
# File 'lib/lutaml/model/type/string.rb', line 53 def self.default_xsd_type "xs:string" end |
.white_space_mode ⇒ Object
Effective xs:whiteSpace mode for this type, defaulting to :preserve. Memoized per class so the hot cast path avoids re-walking the facet chain; class-instance variables are not inherited, so each subclass computes (and freezes) its own effective mode.
36 37 38 |
# File 'lib/lutaml/model/type/string.rb', line 36 def self.white_space_mode @white_space_mode ||= facets[:white_space] || :preserve end |