Method: Pubid::Core::Stage#initialize

Defined in:
lib/pubid/core/stage.rb

#initialize(config:, 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 (String, Float, HarmonizedStageCode) (defaults to: nil)
  • config (Configuration)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pubid/core/stage.rb', line 8

def initialize(config:, abbr: nil, harmonized_code: nil)
  @config = config
  @abbr = abbr&.to_s

  if harmonized_code
    @harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
                         harmonized_code
                       else
                         HarmonizedStageCode.new(harmonized_code, config: config)
                       end
    @abbr ||= lookup_abbr(@harmonized_code.stages)
  end

  if abbr
    raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless config.stages["abbreviations"].key?(abbr.to_s)

    @harmonized_code ||= HarmonizedStageCode.new(lookup_code(abbr), config: config)
  end
end