Class: Pubid::Jcgm::Scheme

Inherits:
Scheme
  • Object
show all
Defined in:
lib/pubid/jcgm/scheme.rb

Instance Attribute Summary

Attributes inherited from Scheme

#identifiers, #languages, #publishers, #stages, #supplement_identifiers, #types

Class Method Summary collapse

Methods inherited from Scheme

#all_identifier_classes, #all_typed_stages, #configure, #identifier_class_index, #initialize, #locate_identifier_klass_by_type_code, #locate_typed_stage_by_abbr, #locate_typed_stage_by_harmonized_code, #locate_typed_stage_by_stage_code, #supplement_typed_stages, #typed_stage_index, #typed_stages

Constructor Details

This class inherits a constructor from Pubid::Scheme

Class Method Details

.identifiersObject



7
8
9
10
11
12
# File 'lib/pubid/jcgm/scheme.rb', line 7

def identifiers
  [
    Identifiers::Guide,
    Identifiers::GumGuide,
  ]
end

.locate_identifier_klass_by_type_code(type_code) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pubid/jcgm/scheme.rb', line 42

def locate_identifier_klass_by_type_code(type_code)
  # Check all identifier classes (base + supplement)
  all_classes = identifiers + supplement_identifiers

  identifier_klass = all_classes.detect do |klass|
    klass.type[:key].to_s == type_code.to_s
  end

  unless identifier_klass
    raise ArgumentError,
          "Unknown type code: #{type_code}"
  end

  identifier_klass
end

.locate_typed_stage_by_abbr(abbr) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pubid/jcgm/scheme.rb', line 26

def locate_typed_stage_by_abbr(abbr)
  # Empty abbr means Guide (published)
  abbr = "" if abbr.nil? || abbr.to_s.strip.empty?

  typed_stage = typed_stages.detect do |ts|
    ts.abbr.include?(abbr)
  end

  unless typed_stage
    raise ArgumentError,
          "Unknown type abbreviation: '#{abbr}'"
  end

  typed_stage
end

.supplement_identifiersObject



14
15
16
17
18
# File 'lib/pubid/jcgm/scheme.rb', line 14

def supplement_identifiers
  [
    Identifiers::Amendment,
  ]
end

.typed_stagesObject



20
21
22
23
24
# File 'lib/pubid/jcgm/scheme.rb', line 20

def typed_stages
  (identifiers + supplement_identifiers).flat_map do |klass|
    klass::TYPED_STAGES
  end
end