Class: Pubid::Iso::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/iso/stage.rb

Constant Summary collapse

STAGES =
{ PWI: "00.00",
NP: "10.00",
AWI: "20.00",
WD: "20.20",
CD: "30.00",
DIS: "40.00",
FDIS: "50.00",
PRF: "50.00",
IS: "60.00" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abbr: nil, harmonized_code: nil) ⇒ Stage

Returns a new instance of Stage.

Parameters:

  • abbr (String, Symbol) (defaults to: nil)

    abbreviation eg. :PWI, :WD

  • harmonized_code (HarmonizedStageCode) (defaults to: nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pubid/iso/stage.rb', line 17

def initialize(abbr: nil, harmonized_code: nil)
  @abbr = abbr
  @harmonized_code = harmonized_code

  if harmonized_code
    # @abbr = STAGES.select { |k,v| v == @harmonized_code.to_s }.first&.first
    @abbr ||= STAGES.key(@harmonized_code.to_s)
  end

  if abbr
    raise Errors::CodeInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)

    @harmonized_code ||= HarmonizedStageCode.new(*STAGES[abbr.to_sym].split("."))
  end
end

Instance Attribute Details

#abbrObject

Returns the value of attribute abbr.



3
4
5
# File 'lib/pubid/iso/stage.rb', line 3

def abbr
  @abbr
end

#harmonized_codeObject

Returns the value of attribute harmonized_code.



3
4
5
# File 'lib/pubid/iso/stage.rb', line 3

def harmonized_code
  @harmonized_code
end