Module: Lutaml::Model::Type
- Defined in:
- lib/lutaml/model/type.rb,
lib/lutaml/model/type/date.rb,
lib/lutaml/model/type/hash.rb,
lib/lutaml/model/type/time.rb,
lib/lutaml/model/type/float.rb,
lib/lutaml/model/type/value.rb,
lib/lutaml/model/type/string.rb,
lib/lutaml/model/type/boolean.rb,
lib/lutaml/model/type/decimal.rb,
lib/lutaml/model/type/integer.rb,
lib/lutaml/model/type/date_time.rb,
lib/lutaml/model/type/time_without_date.rb,
lib/lutaml/model/error/type/invalid_value_error.rb
Defined Under Namespace
Classes: Boolean, Date, DateTime, Decimal, Float, Hash, Integer, InvalidValueError, String, Time, TimeWithoutDate, Value
Constant Summary
collapse
- TYPE_CODES =
{
string: "Lutaml::Model::Type::String",
integer: "Lutaml::Model::Type::Integer",
float: "Lutaml::Model::Type::Float",
decimal: "Lutaml::Model::Type::Decimal",
date: "Lutaml::Model::Type::Date",
time: "Lutaml::Model::Type::Time",
date_time: "Lutaml::Model::Type::DateTime",
time_without_date: "Lutaml::Model::Type::TimeWithoutDate",
boolean: "Lutaml::Model::Type::Boolean",
hash: "Lutaml::Model::Type::Hash",
}.freeze
Class Method Summary
collapse
Class Method Details
.cast(value, type) ⇒ Object
43
44
45
46
47
|
# File 'lib/lutaml/model/type.rb', line 43
def cast(value, type)
return nil if value.nil?
type.cast(value)
end
|
.lookup(type_name) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/lutaml/model/type.rb', line 34
def lookup(type_name)
@registry ||= {}
klass = @registry[type_name.to_sym]
raise UnknownTypeError.new(type_name) unless klass
klass
end
|
.register(type_name, type_class) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/lutaml/model/type.rb', line 24
def register(type_name, type_class)
unless type_class < Value
raise TypeError,
"class '#{type_class}' is not a valid Lutaml::Model::Type::Value"
end
@registry ||= {}
@registry[type_name.to_sym] = type_class
end
|
.register_builtin_types ⇒ Object
18
19
20
21
22
|
# File 'lib/lutaml/model/type.rb', line 18
def register_builtin_types
TYPE_CODES.each do |type_name, type_class|
register(type_name, const_get(type_class))
end
end
|
.serialize(value, type) ⇒ Object
49
50
51
52
53
|
# File 'lib/lutaml/model/type.rb', line 49
def serialize(value, type)
return nil if value.nil?
type.serialize(value)
end
|