Class: Pubid::Iso::Scheme

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

Overview

ISO Scheme with memoized parser/builder and hash-based indexing

Instance Attribute Summary

Attributes inherited from Scheme

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scheme

#all_identifier_classes, #all_typed_stages, #configure, #identifier_class_index, #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

#initializeScheme

Initialize the scheme with identifiers



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/pubid/iso/scheme.rb', line 87

def initialize
  super(
    identifiers: self.class.identifiers,
    supplement_identifiers: [
      Identifiers::Amendment,
      Identifiers::Corrigendum,
      Identifiers::Supplement,
      Identifiers::Extract,
      Identifiers::Addendum,
    ],
  )
end

Class Method Details

.identifiersArray<Class>

Keep existing class methods for backward compatibility

Returns:

  • (Array<Class>)

    all base identifier classes



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pubid/iso/scheme.rb', line 47

def identifiers
  [
    Identifiers::InternationalStandard,
    Identifiers::TechnicalReport,
    Identifiers::TechnicalSpecification,
    Identifiers::Guide,
    Identifiers::Pas,
    Identifiers::Data,
    Identifiers::TechnologyTrendsAssessments,
    Identifiers::InternationalWorkshopAgreement,
    Identifiers::InternationalStandardizedProfile,
    Identifiers::Recommendation,
    Identifiers::Directives,
    Identifiers::Amendment,
    Identifiers::Corrigendum,
    Identifiers::Supplement,
    Identifiers::Extract,
    Identifiers::DirectivesSupplement,
    Identifiers::Addendum,
    Identifiers::TcDocument,
  ]
end

.instancePubid::Iso::Scheme

Singleton instance for memoization

Returns:



10
11
12
# File 'lib/pubid/iso/scheme.rb', line 10

def instance
  @instance ||= new
end

.locate_identifier_klass_by_type_code(type_code) ⇒ Class

Returns the matching identifier class.

Parameters:

  • type_code (String, Symbol)

    the type code to find

Returns:

  • (Class)

    the matching identifier class



29
30
31
# File 'lib/pubid/iso/scheme.rb', line 29

def locate_identifier_klass_by_type_code(type_code)
  instance.locate_identifier_klass_by_type_code(type_code)
end

.locate_typed_stage_by_abbr(abbr) ⇒ TypedStage

Returns the matching typed stage.

Parameters:

  • abbr (String, Symbol)

    the abbreviation to find

Returns:

  • (TypedStage)

    the matching typed stage



23
24
25
# File 'lib/pubid/iso/scheme.rb', line 23

def locate_typed_stage_by_abbr(abbr)
  instance.locate_typed_stage_by_abbr(abbr)
end

.locate_typed_stage_by_harmonized_code(harmonized_code) ⇒ TypedStage?

Returns the matching typed stage.

Parameters:

  • harmonized_code (String)

    the harmonized stage code to find

Returns:

  • (TypedStage, nil)

    the matching typed stage



41
42
43
# File 'lib/pubid/iso/scheme.rb', line 41

def locate_typed_stage_by_harmonized_code(harmonized_code)
  instance.locate_typed_stage_by_harmonized_code(harmonized_code)
end

.locate_typed_stage_by_stage_code(stage_code) ⇒ TypedStage

Returns the matching typed stage.

Parameters:

  • stage_code (String, Symbol)

    the stage code to find

Returns:

  • (TypedStage)

    the matching typed stage



35
36
37
# File 'lib/pubid/iso/scheme.rb', line 35

def locate_typed_stage_by_stage_code(stage_code)
  instance.locate_typed_stage_by_stage_code(stage_code)
end

.parse(identifier) ⇒ Identifier

Delegate class methods to singleton instance for backward compatibility

Parameters:

  • identifier (String)

    the identifier string to parse

Returns:



17
18
19
# File 'lib/pubid/iso/scheme.rb', line 17

def parse(identifier)
  instance.parse(identifier)
end

.supplement_typed_stagesObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/pubid/iso/scheme.rb', line 74

def supplement_typed_stages
  supplement_identifiers = [
    Identifiers::Amendment,
    Identifiers::Corrigendum,
    Identifiers::Supplement,
    Identifiers::Extract,
    Identifiers::Addendum,
  ]
  supplement_identifiers.flat_map { |klass| klass::TYPED_STAGES }
end

.typed_stagesObject



70
71
72
# File 'lib/pubid/iso/scheme.rb', line 70

def typed_stages
  identifiers.flat_map { |klass| klass::TYPED_STAGES }.compact
end

Instance Method Details

#parse(identifier) ⇒ Identifier

Parse an ISO identifier string using memoized parser/builder

Parameters:

  • identifier (String)

    the identifier string to parse

Returns:



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/pubid/iso/scheme.rb', line 103

def parse(identifier)
  # Handle DAD/FDAD patterns that parser can't recognize
  if match = identifier.match(/^(.+?)\/(F?DAD)\s+(\d+)(?::(\d{4}))?$/)
    parse_dad_pattern(match)
  else
    # Apply legacy update_codes normalization first, before any other preprocessing
    normalized = Core::UpdateCodes.apply(identifier, :iso)
    # Normalize Cyrillic (Russian) identifiers to Latin equivalents
    normalized = normalize_cyrillic(normalized)
    parsed = parser.parse(normalized)
    builder.build(parsed)
  end
end