Module: Pubid::Iso
- Extended by:
- PrefixesSupport
- 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
Constant Summary collapse
- PREFIXES =
Sole ISO publisher token. Joint / co-publication forms (ISO/IEC, IEC/ISO, ISO/IEC/IEEE) are contributed symmetrically via Pubid::JOINT_PREFIXES.
["ISO"].freeze
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.
Methods included from PrefixesSupport
Class Method Details
.all_typed_stages ⇒ Array<Pubid::Components::TypedStage>
Build typed stage index from identifier types
161 162 163 164 165 166 167 168 169 |
# File 'lib/pubid/iso.rb', line 161 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.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pubid/iso.rb', line 67 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.
134 135 136 |
# File 'lib/pubid/iso.rb', line 134 def self.build_from_parse(hash) builder.build(hash) end |
.builder ⇒ Pubid::Iso::Builder
Memoized builder instance used by Normalizer / URN parser
173 174 175 |
# File 'lib/pubid/iso.rb', line 173 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)
225 226 227 |
# File 'lib/pubid/iso.rb', line 225 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
152 153 154 155 156 157 |
# File 'lib/pubid/iso.rb', line 152 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.
146 147 148 |
# File 'lib/pubid/iso.rb', line 146 def self.joint_grammar_atom(rule_name) parser.public_send(rule_name) end |
.locate_stage(abbr) ⇒ Pubid::Components::TypedStage?
Lookup: abbreviation -> typed stage
193 194 195 196 |
# File 'lib/pubid/iso.rb', line 193 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
209 210 211 212 |
# File 'lib/pubid/iso.rb', line 209 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
217 218 219 220 |
# File 'lib/pubid/iso.rb', line 217 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
201 202 203 204 |
# File 'lib/pubid/iso.rb', line 201 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
186 187 188 |
# File 'lib/pubid/iso.rb', line 186 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pubid/iso.rb', line 33 def self.parse(identifier, format: :auto) if identifier.length > Pubid::MAX_INPUT_LENGTH raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE end 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
122 123 124 |
# File 'lib/pubid/iso.rb', line 122 def self.parse_urn(urn) UrnParser.parse(urn) end |
.parser ⇒ Pubid::Iso::Parser
Memoized parser instance used by Normalizer
179 180 181 |
# File 'lib/pubid/iso.rb', line 179 def self.parser @parser ||= Parser.new end |