Class: Pubid::W3c::Identifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::W3c::Identifier
- Defined in:
- lib/pubid/w3c/identifier.rb
Overview
Base class for every W3C identifier AND the flavor's parse/create entry point. Concrete identifiers under Pubid::W3c::Identifiers descend from this class (one per W3C maturity level), so a parsed W3C id is an instance of Pubid::W3c::Identifier.
W3C identifiers are flat: a slug code, an optional publication date
(kept verbatim as a string — width varies: 8-digit YYYYMMDD, or legacy
6-digit YYMMDD / 4-digit MMDD), and a document-type carried by the
concrete class (its type_prefix returns the printed token, e.g. "WD").
Direct Known Subclasses
Pubid::W3c::Identifiers::CandidateRecommendation, Pubid::W3c::Identifiers::CandidateRecommendationDraft, Pubid::W3c::Identifiers::DraftNote, Pubid::W3c::Identifiers::Note, Pubid::W3c::Identifiers::ObsoleteRecommendation, Pubid::W3c::Identifiers::ProposedEditedRecommendation, Pubid::W3c::Identifiers::ProposedRecommendation, Pubid::W3c::Identifiers::Recommendation, Pubid::W3c::Identifiers::Standard, Pubid::W3c::Identifiers::SupersededRecommendation, Pubid::W3c::Identifiers::WorkingDraft
Constant Summary collapse
- W3C_TYPE_MAP =
Polymorphic type map for lutaml::Model key_value (de)serialization: maps each subclass's polymorphic_name to its class name so a stored hash rebuilds the correct identifier type via from_hash.
{ "pubid:w3c:standard" => "Pubid::W3c::Identifiers::Standard", "pubid:w3c:note" => "Pubid::W3c::Identifiers::Note", "pubid:w3c:draft-note" => "Pubid::W3c::Identifiers::DraftNote", "pubid:w3c:working-draft" => "Pubid::W3c::Identifiers::WorkingDraft", "pubid:w3c:candidate-recommendation" => "Pubid::W3c::Identifiers::CandidateRecommendation", "pubid:w3c:candidate-recommendation-draft" => "Pubid::W3c::Identifiers::CandidateRecommendationDraft", "pubid:w3c:recommendation" => "Pubid::W3c::Identifiers::Recommendation", "pubid:w3c:proposed-recommendation" => "Pubid::W3c::Identifiers::ProposedRecommendation", "pubid:w3c:proposed-edited-recommendation" => "Pubid::W3c::Identifiers::ProposedEditedRecommendation", "pubid:w3c:superseded-recommendation" => "Pubid::W3c::Identifiers::SupersededRecommendation", "pubid:w3c:obsolete-recommendation" => "Pubid::W3c::Identifiers::ObsoleteRecommendation", }.freeze
- PUBLISHER =
Publisher is always "W3C". A plain constant (not a
publishermethod) so it doesn't shadow the inherited lutamlpublisherattribute, which would otherwise fail serialization type validation. "W3C"
Instance Attribute Summary collapse
-
#with_publisher ⇒ Object
readonly
Returns the value of attribute with_publisher.
Class Method Summary collapse
-
.parse(identifier) ⇒ Identifier
Parse a W3C identifier string into an identifier object.
Instance Method Summary collapse
- #to_s(with_publisher: true, **opts) ⇒ Object
-
#type_prefix ⇒ Object
The printed document-type token (e.g. "WD").
-
#year ⇒ Object
Publication year derived from an 8-digit YYYYMMDD date, else nil.
Methods inherited from Identifier
apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code
Constructor Details
This class inherits a constructor from Pubid::Identifier
Instance Attribute Details
#with_publisher ⇒ Object (readonly)
Returns the value of attribute with_publisher.
64 65 66 |
# File 'lib/pubid/w3c/identifier.rb', line 64 def with_publisher @with_publisher end |
Class Method Details
.parse(identifier) ⇒ Identifier
Parse a W3C identifier string into an identifier object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pubid/w3c/identifier.rb', line 87 def self.parse(identifier) # Reject pathological inputs before they reach the parser # (CodeQL rb/polynomial-redos barrier — inline .length by design). if identifier.length > Pubid::MAX_INPUT_LENGTH raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE end parsed = Parser.parse(identifier) Builder.build(parsed) rescue Parslet::ParseFailed => e raise "Failed to parse W3C identifier '#{identifier}': #{e.}" end |
Instance Method Details
#to_s(with_publisher: true, **opts) ⇒ Object
75 76 77 78 |
# File 'lib/pubid/w3c/identifier.rb', line 75 def to_s(with_publisher: true, **opts) @with_publisher = with_publisher render(format: :human, **opts) end |
#type_prefix ⇒ Object
The printed document-type token (e.g. "WD"). nil for the bare-code Standard form; concrete typed subclasses override it.
60 61 62 |
# File 'lib/pubid/w3c/identifier.rb', line 60 def type_prefix nil end |
#year ⇒ Object
Publication year derived from an 8-digit YYYYMMDD date, else nil. date
is a plain string here (not a Components::Date), so the inherited
year — which calls date&.year — would break; override it.
69 70 71 72 73 |
# File 'lib/pubid/w3c/identifier.rb', line 69 def year return nil unless date.is_a?(::String) && date.length == 8 date[0, 4] end |