Module: Pubid::Iso
- Defined in:
- lib/pubid/iso.rb,
lib/pubid/iso/parser.rb,
lib/pubid/iso/builder.rb,
lib/pubid/iso/utilities.rb,
lib/pubid/iso/components.rb,
lib/pubid/iso/identifier.rb,
lib/pubid/iso/normalizer.rb,
lib/pubid/iso/urn_parser.rb,
lib/pubid/iso/identifiers.rb,
lib/pubid/iso/urn_generator.rb,
lib/pubid/iso/components/code.rb,
lib/pubid/iso/format_resolver.rb,
lib/pubid/iso/identifiers/pas.rb,
lib/pubid/iso/rendering_style.rb,
lib/pubid/iso/identifiers/data.rb,
lib/pubid/iso/identifiers/guide.rb,
lib/pubid/iso/single_identifier.rb,
lib/pubid/iso/bundled_identifier.rb,
lib/pubid/iso/combined_identifier.rb,
lib/pubid/iso/identifiers/extract.rb,
lib/pubid/iso/components/publisher.rb,
lib/pubid/iso/identifiers/addendum.rb,
lib/pubid/iso/identifiers/amendment.rb,
lib/pubid/iso/supplement_identifier.rb,
lib/pubid/iso/identifiers/directives.rb,
lib/pubid/iso/identifiers/supplement.rb,
lib/pubid/iso/identifiers/corrigendum.rb,
lib/pubid/iso/identifiers/tc_document.rb,
lib/pubid/iso/identifiers/recommendation.rb,
lib/pubid/iso/identifiers/technical_report.rb,
lib/pubid/iso/identifiers/directives_supplement.rb,
lib/pubid/iso/identifiers/international_standard.rb,
lib/pubid/iso/identifiers/technical_specification.rb,
lib/pubid/iso/identifiers/technology_trends_assessments.rb,
lib/pubid/iso/identifiers/international_workshop_agreement.rb,
lib/pubid/iso/identifiers/international_standardized_profile.rb
Defined Under Namespace
Modules: Components, Identifiers, Utilities Classes: Builder, BundledIdentifier, CombinedIdentifier, FormatResolver, Identifier, Normalizer, Parser, RefDated, RefDatedLong, RefNumLong, RefNumShort, RefUndated, RefUndatedLong, RenderingStyle, SingleIdentifier, SupplementIdentifier, UrnGenerator, UrnParser
Class Method Summary collapse
-
.all_typed_stages ⇒ Array<Pubid::Components::TypedStage>
Build typed stage index from identifier types.
-
.build(type:, publisher: nil, copublishers: nil, number: nil, year: nil, **attrs) ⇒ Pubid::Iso::Identifier
Build an ISO identifier from attributes.
-
.build_from_parse(hash) ⇒ Pubid::Iso::Identifier
Build an ISO identifier from a Parslet parse-tree hash (used by other flavors when parsing joint identifiers, e.g. IEC’s ‘IEC … | ISO …` form).
-
.builder ⇒ Pubid::Iso::Builder
Memoized builder instance used by Normalizer / URN parser.
-
.default_typed_stage ⇒ Pubid::Components::TypedStage
Default typed stage used when no type_with_stage is present (e.g., the bare International Standard published stage).
-
.identifier_types ⇒ Array<Class>
Auto-discover all identifier types from the Identifiers namespace.
-
.joint_grammar_atom(rule_name) ⇒ Parslet::Atoms::Base
Return the named Parslet rule atom from the ISO parser, for embedding in another flavor’s grammar (e.g. IEC joint identifiers).
-
.locate_stage(abbr) ⇒ Pubid::Components::TypedStage?
Lookup: abbreviation -> typed stage.
-
.locate_stage_by_code(code) ⇒ Pubid::Components::TypedStage?
Lookup: per-typed-stage code -> typed stage.
-
.locate_stage_by_harmonized_code(harmonized_code) ⇒ Pubid::Components::TypedStage?
Lookup: harmonized stage code -> typed stage.
-
.locate_stage_by_stage_code(stage_code) ⇒ Pubid::Components::TypedStage?
Lookup: stage code -> typed stage.
-
.locate_type(code) ⇒ Class?
Lookup: type code -> identifier class.
-
.parse(identifier, format: :auto) ⇒ Identifier
Parse an ISO identifier string.
-
.parse_urn(urn) ⇒ Identifier
Parse an ISO URN string.
-
.parser ⇒ Pubid::Iso::Parser
Memoized parser instance used by Normalizer.
Class Method Details
.all_typed_stages ⇒ Array<Pubid::Components::TypedStage>
Build typed stage index from identifier types
151 152 153 154 155 156 157 158 159 |
# File 'lib/pubid/iso.rb', line 151 def self.all_typed_stages @all_typed_stages ||= identifier_types.flat_map do |klass| if klass.const_defined?(:TYPED_STAGES) klass.const_get(:TYPED_STAGES) else [] end end end |
.build(type:, publisher: nil, copublishers: nil, number: nil, year: nil, **attrs) ⇒ Pubid::Iso::Identifier
Build an ISO identifier from attributes.
This is the public seam: callers in other flavors should never reach into ‘Pubid::Iso::Identifiers::*` or `Pubid::Iso::Components::*` directly — go through this method so the internal class registry can change without breaking callers.
Accepts either raw values (Strings/Integers) or pre-built components. Raw values are wrapped in the appropriate ISO component internally.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pubid/iso.rb', line 57 def self.build(type:, publisher: nil, copublishers: nil, number: nil, year: nil, **attrs) klass = locate_type(type) || raise(ArgumentError, "unknown ISO type: #{type.inspect}") copub_list = Array(copublishers) attrs[:publisher] = build_publisher(publisher, copub_list) if publisher || copub_list.any? attrs[:copublishers] = build_copublishers(copub_list) if copub_list.any? attrs[:number] = build_code(number) if number attrs[:date] = build_date(year) if year klass.new(attrs) end |
.build_from_parse(hash) ⇒ Pubid::Iso::Identifier
Build an ISO identifier from a Parslet parse-tree hash (used by other flavors when parsing joint identifiers, e.g. IEC’s ‘IEC … | ISO …` form).
This is the public seam: callers should never reach into ‘Pubid::Iso::Builder` directly.
124 125 126 |
# File 'lib/pubid/iso.rb', line 124 def self.build_from_parse(hash) builder.build(hash) end |
.builder ⇒ Pubid::Iso::Builder
Memoized builder instance used by Normalizer / URN parser
163 164 165 |
# File 'lib/pubid/iso.rb', line 163 def self.builder @builder ||= Builder.new end |
.default_typed_stage ⇒ Pubid::Components::TypedStage
Default typed stage used when no type_with_stage is present (e.g., the bare International Standard published stage)
215 216 217 |
# File 'lib/pubid/iso.rb', line 215 def self.default_typed_stage locate_stage("") || all_typed_stages.first end |
.identifier_types ⇒ Array<Class>
Auto-discover all identifier types from the Identifiers namespace
142 143 144 145 146 147 |
# File 'lib/pubid/iso.rb', line 142 def self.identifier_types @identifier_types ||= Identifiers.constants .filter_map { |c| begin; Identifiers.const_get(c); rescue NameError; nil; end } .select { |c| c.is_a?(Class) && c.singleton_methods(false).include?(:type) } .select { |c| c.type.is_a?(Hash) } end |
.joint_grammar_atom(rule_name) ⇒ Parslet::Atoms::Base
Return the named Parslet rule atom from the ISO parser, for embedding in another flavor’s grammar (e.g. IEC joint identifiers).
This is the public seam: callers should never instantiate ‘Pubid::Iso::Parser` directly.
136 137 138 |
# File 'lib/pubid/iso.rb', line 136 def self.joint_grammar_atom(rule_name) parser.public_send(rule_name) end |
.locate_stage(abbr) ⇒ Pubid::Components::TypedStage?
Lookup: abbreviation -> typed stage
183 184 185 186 |
# File 'lib/pubid/iso.rb', line 183 def self.locate_stage(abbr) abbr_str = abbr.to_s.upcase all_typed_stages.find { |s| s.abbr.any? { |a| a.to_s.upcase == abbr_str } } end |
.locate_stage_by_code(code) ⇒ Pubid::Components::TypedStage?
Lookup: per-typed-stage code -> typed stage
199 200 201 202 |
# File 'lib/pubid/iso.rb', line 199 def self.locate_stage_by_code(code) code_sym = code.to_sym all_typed_stages.find { |s| s.code&.to_sym == code_sym } end |
.locate_stage_by_harmonized_code(harmonized_code) ⇒ Pubid::Components::TypedStage?
Lookup: harmonized stage code -> typed stage
207 208 209 210 |
# File 'lib/pubid/iso.rb', line 207 def self.locate_stage_by_harmonized_code(harmonized_code) harmonized_str = harmonized_code.to_s all_typed_stages.find { |s| s.harmonized_stages&.include?(harmonized_str) } end |
.locate_stage_by_stage_code(stage_code) ⇒ Pubid::Components::TypedStage?
Lookup: stage code -> typed stage
191 192 193 194 |
# File 'lib/pubid/iso.rb', line 191 def self.locate_stage_by_stage_code(stage_code) stage_code_sym = stage_code.to_sym all_typed_stages.find { |s| s.stage_code.to_sym == stage_code_sym } end |
.locate_type(code) ⇒ Class?
Lookup: type code -> identifier class
176 177 178 |
# File 'lib/pubid/iso.rb', line 176 def self.locate_type(code) identifier_types.find { |t| t.type[:key].to_s == code.to_s } end |
.parse(identifier, format: :auto) ⇒ Identifier
Parse an ISO identifier string
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pubid/iso.rb', line 27 def self.parse(identifier, format: :auto) format = Pubid::FormatDetector.detect(identifier) if format == :auto case format when :urn UrnParser.parse(identifier) when :mr_string Pubid::Parsers::MrString.parse(identifier) else Normalizer.apply(identifier) end end |
.parse_urn(urn) ⇒ Identifier
Parse an ISO URN string
112 113 114 |
# File 'lib/pubid/iso.rb', line 112 def self.parse_urn(urn) UrnParser.parse(urn) end |
.parser ⇒ Pubid::Iso::Parser
Memoized parser instance used by Normalizer
169 170 171 |
# File 'lib/pubid/iso.rb', line 169 def self.parser @parser ||= Parser.new end |