Class: Dcc::Type::SchemaVersion

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

Overview

DCC schemaVersion attribute (e.g. "3.3.0", "3.4.0-rc.2"). Validates the format on cast. Use Dcc::Schema::Version.major(v) to extract the major number from any version string.

Constant Summary collapse

PATTERN =
/\A
  (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)
  (?:-(?<pre>[0-9A-Za-z.-]+))?
  (?:\+(?<build>[0-9A-Za-z.-]+))?
\z/x.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cast(value) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/dcc/type/schema_version.rb', line 17

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

  unless PATTERN.match?(value)
    raise Lutaml::Model::Type::InvalidValueError.new(value, "invalid schemaVersion")
  end

  value
end

.extract_major(value) ⇒ Object



31
32
33
34
# File 'lib/dcc/type/schema_version.rb', line 31

def self.extract_major(value)
  m = PATTERN.match(value.to_s)
  m && Integer(m[:major])
end

Instance Method Details

#majorObject



27
28
29
# File 'lib/dcc/type/schema_version.rb', line 27

def major
  self.class.extract_major(to_s)
end