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) ⇒ 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.
-
#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) ⇒ Object
14 15 16 17 18 |
# File 'lib/lutaml/model/type/value.rb', line 14 def self.cast(value) return nil if value.nil? value end |
.from_format(value, format) ⇒ Object
Class-level format conversion
32 33 34 |
# File 'lib/lutaml/model/type/value.rb', line 32 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/lutaml/model/type/value.rb', line 37 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
20 21 22 23 24 |
# File 'lib/lutaml/model/type/value.rb', line 20 def self.serialize(value) return nil if value.nil? new(value).to_s end |
Instance Method Details
#to_s ⇒ Object
Instance methods for serialization
27 28 29 |
# File 'lib/lutaml/model/type/value.rb', line 27 def to_s value.to_s end |