Class: Lutaml::Model::Type::Time
- Defined in:
- lib/lutaml/model/type/time.rb
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
Instance Method Summary collapse
-
#to_xml ⇒ Object
# xs:time format (HH:MM:SS.mmm±HH:MM).
-
#to_yaml ⇒ Object
YAML timestamp format (native).
Methods inherited from Value
from_format, #initialize, #initialized?, register_format_to_from_methods, #to_s
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value, _options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lutaml/model/type/time.rb', line 7 def self.cast(value, = {}) return value if value.nil? || Utils.uninitialized?(value) case value when ::Time then value when ::DateTime then value.to_time else ::Time.parse(value.to_s) end rescue ArgumentError nil end |
.serialize(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lutaml/model/type/time.rb', line 19 def self.serialize(value) return value if value.nil? || Utils.uninitialized?(value) value = cast(value) # value&.strftime("%Y-%m-%dT%H:%M:%S%:z") value&.iso8601 end |
Instance Method Details
#to_xml ⇒ Object
# xs:time format (HH:MM:SS.mmm±HH:MM)
28 29 30 |
# File 'lib/lutaml/model/type/time.rb', line 28 def to_xml value&.iso8601 end |
#to_yaml ⇒ Object
YAML timestamp format (native)
38 39 40 |
# File 'lib/lutaml/model/type/time.rb', line 38 def to_yaml value&.iso8601 end |