Class: Pubid::Iec::Identifier
- Inherits:
-
Pubid::Identifier
- Object
- Lutaml::Model::Serializable
- Pubid::Identifier
- Pubid::Iec::Identifier
- Defined in:
- lib/pubid/iec/identifier.rb
Direct Known Subclasses
Pubid::Iec::Identifiers::ConsolidatedIdentifier, Pubid::Iec::Identifiers::FragmentIdentifier, Pubid::Iec::Identifiers::SheetIdentifier, Pubid::Iec::Identifiers::VapIdentifier, SingleIdentifier
Constant Summary collapse
- EXTRA_CREATE_KLASS_FILES =
Long-tail document types that ‘create` may build but which are not in Scheme.identifiers (the parse/build candidate set). Loaded lazily (not at require time) to avoid a circular load with identifiers/base.rb.
%w[ conformity_assessment technology_report white_paper societal_technology_trend_report systems_reference_document interpretation_sheet ].freeze
Class Method Summary collapse
-
.create(type: nil, stage: nil, **opts) ⇒ Object
Factory mirroring pubid 1.x’s ‘Pubid::Iec::Identifier.create` API.
- .parse(string) ⇒ Object
Methods inherited from Pubid::Identifier
#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_s, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
This class inherits a constructor from Pubid::Identifier
Class Method Details
.create(type: nil, stage: nil, **opts) ⇒ Object
Factory mirroring pubid 1.x’s ‘Pubid::Iec::Identifier.create` API. See Pubid::Iso::Identifier.create for the shared design. Builds the IEC `Components::*` subclasses (not the base ones) and populates type/stage from the resolved TypedStage, so that a created identifier round-trips `==` against the same identifier produced by `parse`.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pubid/iec/identifier.rb', line 39 def self.create(type: nil, stage: nil, **opts) # A VAP suffix (CSV/RLV/…) is the outermost wrapper around the base # document (which may itself be amended); rebuild it first. if (vap = opts.delete(:vap)) base = create(type: type, stage: stage, **opts) return Identifiers::VapIdentifier.new( base_identifier: base, vap_suffix: Components::VapSuffix.new(code: Array(vap).first.to_s), ) end # Structured index rows carry amendments/corrigendums as a flat list # alongside the base document's keys; rebuild the supplement wrapping # the recursively-created base, mirroring what parse produces. if (supp = extract_supplement(opts)) return build_supplement(supp, type: type, stage: stage, opts: opts) end # A nested base: holds the base document of a supplement whose own # number/year sit at the top level (e.g. an Interpretation Sheet). if (base_hash = opts.delete(:base)) return build_based_supplement(type: type, base_hash: base_hash, opts: opts) end klass = resolve_create_class(type: type, stage: stage) attrs = coerce_create_attrs(opts) ts = resolve_create_typed_stage(klass, stage) if ts attrs[:typed_stage] = ts # Parse derives `type` and `stage` from the TypedStage (see # Builder#cast for :type_with_stage); mirror that here. attrs[:type] ||= ts.to_type attrs[:stage] ||= ts.to_stage end klass.new(**attrs) end |
.parse(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pubid/iec/identifier.rb', line 17 def self.parse(string) # Route URN strings to the URN parser (mirrors Iso::Identifier.parse) if Pubid::FormatDetector.detect(string) == :urn return Pubid::Iec::UrnParser.parse(string) end # Apply legacy update_codes normalization first, before any other preprocessing normalized = Core::UpdateCodes.apply(string, :iec) parsed = Pubid::Iec::Parser.new.parse(normalized) if parsed.nil? || parsed.empty? raise Pubid::Iec::Parser::ParseError, "Invalid identifier format" end Pubid::Iec::Builder.new(Pubid::Iec::Scheme).build(parsed) end |