Sha256: e3e11c77d206e572117355c4e15395f77ce462a672426c7b8ea128a727a2b33d

Contents?: true

Size: 682 Bytes

Versions: 5

Compression:

Stored size: 682 Bytes

Contents

STAGES = YAML.load_file(File.join(File.dirname(__FILE__), "../../stages.yaml"))

module NistPubid
  class Stage
    attr_accessor :stage, :original_code

    def initialize(original_code)
      self.original_code = original_code
      @stage = self.class.regexp.match(original_code)&.[](1)
    end

    def to_s(format = :short)
      return "" if nil?

      case format
      when :short
        "(#{@stage})"
      when :mr
        @stage
      else
        STAGES[@stage]
      end
    end

    def self.parse(code)
      new(regexp.match(code)&.to_s)
    end

    def self.regexp
      /\((#{STAGES.keys.join('|')})\)/
    end

    def nil?
      @stage.nil?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nist-pubid-0.1.7 lib/nist_pubid/stage.rb
nist-pubid-0.1.6 lib/nist_pubid/stage.rb
nist-pubid-0.1.5 lib/nist_pubid/stage.rb
nist-pubid-0.1.4 lib/nist_pubid/stage.rb
nist-pubid-0.1.3 lib/nist_pubid/stage.rb