Class: Lutaml::Model::Type::String

Inherits:
Value
  • Object
show all
Defined in:
lib/lutaml/model/type/string.rb

Instance Attribute Summary

Attributes inherited from Value

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

from_format, #initialize, #initialized?, register_format_to_from_methods, serialize, #to_s

Constructor Details

This class inherits a constructor from Lutaml::Model::Type::Value

Class Method Details

.cast(value, options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/lutaml/model/type/string.rb', line 5

def self.cast(value, options = {})
  return nil if value.nil?

  value = value.to_s
  Model::Services::Type::Validator::String.validate!(value, options)
  value
end

.from_json(value) ⇒ Object



37
38
39
# File 'lib/lutaml/model/type/string.rb', line 37

def self.from_json(value)
  cast(value)
end

.from_toml(value) ⇒ Object



45
46
47
# File 'lib/lutaml/model/type/string.rb', line 45

def self.from_toml(value)
  cast(value)
end

.from_xml(value) ⇒ Object



33
34
35
# File 'lib/lutaml/model/type/string.rb', line 33

def self.from_xml(value)
  cast(value)
end

.from_yaml(value) ⇒ Object



41
42
43
# File 'lib/lutaml/model/type/string.rb', line 41

def self.from_yaml(value)
  cast(value)
end

Instance Method Details

#to_json(*_args) ⇒ Object

JSON string



19
20
21
# File 'lib/lutaml/model/type/string.rb', line 19

def to_json(*_args)
  value
end

#to_tomlObject

TOML string



29
30
31
# File 'lib/lutaml/model/type/string.rb', line 29

def to_toml
  value&.to_s
end

#to_xmlObject

xs:string format



14
15
16
# File 'lib/lutaml/model/type/string.rb', line 14

def to_xml
  value&.to_s
end

#to_yamlObject

YAML string



24
25
26
# File 'lib/lutaml/model/type/string.rb', line 24

def to_yaml
  value
end