Class: Pubid::Iso::Scheme
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
-
.identifiers ⇒ Array<Class>
Keep existing class methods for backward compatibility.
-
.instance ⇒ Pubid::Iso::Scheme
Singleton instance for memoization.
-
.locate_identifier_klass_by_type_code(type_code) ⇒ Class
The matching identifier class.
-
.locate_typed_stage_by_abbr(abbr) ⇒ TypedStage
The matching typed stage.
-
.locate_typed_stage_by_harmonized_code(harmonized_code) ⇒ TypedStage?
The matching typed stage.
-
.locate_typed_stage_by_stage_code(stage_code) ⇒ TypedStage
The matching typed stage.
-
.parse(identifier) ⇒ Identifier
Delegate class methods to singleton instance for backward compatibility.
- .supplement_typed_stages ⇒ Object
- .typed_stages ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Scheme
constructor
Initialize the scheme with identifiers.
-
#parse(identifier) ⇒ Identifier
Parse an ISO identifier string using memoized parser/builder.
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
#initialize ⇒ Scheme
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
.identifiers ⇒ Array<Class>
Keep existing class methods for backward compatibility
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 |
.instance ⇒ Pubid::Iso::Scheme
Singleton instance for memoization
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.
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.
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.
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.
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
17 18 19 |
# File 'lib/pubid/iso/scheme.rb', line 17 def parse(identifier) instance.parse(identifier) end |
.supplement_typed_stages ⇒ Object
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_stages ⇒ Object
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
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 |