Class: Pubid::Nist::Components::Stage

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/nist/components/stage.rb

Overview

Stage component for NIST draft identifiers Combines id (i/f/1-9) with type (pd/wd/prd)

Examples:

Stage.new(id: "i", type: "pd").to_s(:short) # => "ipd"
Stage.new(id: "f", type: "pd").to_s(:long)  # => "(Final Public Draft)"

Constant Summary collapse

STAGES =

Load stages from V1 YAML config

YAML.load_file(
  File.join(File.dirname(__FILE__),
            "../../../../archived-gems/pubid-nist/stages.yaml"),
).freeze

Instance Method Summary collapse

Instance Method Details

#to_s(format = :short) ⇒ String

Render stage in specified format

Parameters:

  • format (:short, :mr, :long) (defaults to: :short)

    The output format

Returns:

  • (String)

    The formatted stage representation



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pubid/nist/components/stage.rb', line 28

def to_s(format = :short)
  return "" if id.nil? || type.nil?

  case format
  when :short, :mr
    "#{id}#{type}"
  when :long
    "(#{STAGES['id'][id]} #{STAGES['type'][type]})"
  else
    "#{id}#{type}"
  end
end

#validate!Object

Validate stage id and type against YAML config



42
43
44
45
46
47
48
49
# File 'lib/pubid/nist/components/stage.rb', line 42

def validate!
  unless STAGES["id"].key?(id.to_s)
    raise ArgumentError, "Invalid stage id: #{id.inspect}"
  end
  unless STAGES["type"].key?(type.to_s)
    raise ArgumentError, "Invalid stage type: #{type.inspect}"
  end
end