Class: Dcc::Type::SiUnit

Inherits:
Lutaml::Model::Type::String
  • Object
show all
Defined in:
lib/dcc/type/si_unit.rb

Overview

D-SI unit expression in siunitx notation (e.g. "\kelvin", "\meter\per\second\squared"). The full siunitx grammar is enforced by the D-SI ontology's SHACL profile; here we apply a lightweight syntactic check: the string must not contain whitespace (Schematron rule), and the non-SI declaration prefix (|unit) is allowed.

Constant Summary collapse

NO_WHITESPACE_PATTERN =
/\A\S+\z/.freeze

Class Method Summary collapse

Class Method Details

.cast(value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/dcc/type/si_unit.rb', line 15

def self.cast(value)
  return nil unless value.is_a?(::String) && value != ""

  unless NO_WHITESPACE_PATTERN.match?(value)
    raise Lutaml::Model::Type::InvalidValueError.new(value, "invalid SI unit expression (whitespace not allowed): #{value.inspect}")
  end

  value
end