Class: Lutaml::Model::Type::Value
- Inherits:
-
Object
- Object
- Lutaml::Model::Type::Value
- Defined in:
- lib/lutaml/model/type/value.rb
Overview
Base class for all value types
Direct Known Subclasses
Boolean, Date, DateTime, Decimal, Float, Hash, Integer, String, Time, TimeWithoutDate
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .cast(value, _options = {}) ⇒ Object
-
.from_format(value, format) ⇒ Object
Class-level format conversion.
-
.register_format_to_from_methods(format) ⇒ Object
called from config when a new format is added.
- .serialize(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(value) ⇒ Value
constructor
A new instance of Value.
- #initialized? ⇒ Boolean
-
#to_s ⇒ Object
Instance methods for serialization.
Constructor Details
#initialize(value) ⇒ Value
Returns a new instance of Value.
10 11 12 |
# File 'lib/lutaml/model/type/value.rb', line 10 def initialize(value) @value = self.class.cast(value) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/lutaml/model/type/value.rb', line 8 def value @value end |
Class Method Details
.cast(value, _options = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/lutaml/model/type/value.rb', line 18 def self.cast(value, = {}) return nil if value.nil? value end |
.from_format(value, format) ⇒ Object
Class-level format conversion
36 37 38 |
# File 'lib/lutaml/model/type/value.rb', line 36 def self.from_format(value, format) new(send(:"from_#{format}", value)) end |
.register_format_to_from_methods(format) ⇒ Object
called from config when a new format is added
41 42 43 44 45 46 47 48 49 |
# File 'lib/lutaml/model/type/value.rb', line 41 def self.register_format_to_from_methods(format) define_method(:"to_#{format}") do value end define_singleton_method(:"from_#{format}") do |value| cast(value) end end |
.serialize(value) ⇒ Object
24 25 26 27 28 |
# File 'lib/lutaml/model/type/value.rb', line 24 def self.serialize(value) return nil if value.nil? new(value).to_s end |
Instance Method Details
#initialized? ⇒ Boolean
14 15 16 |
# File 'lib/lutaml/model/type/value.rb', line 14 def initialized? true end |
#to_s ⇒ Object
Instance methods for serialization
31 32 33 |
# File 'lib/lutaml/model/type/value.rb', line 31 def to_s value.to_s end |