Library
API Reference
Top-Level Methods
Pubid::{Flavor}.parse(string)
Parse a publication identifier string into an identifier object.
id = Pubid::Iso.parse("ISO 9001:2015")id = Pubid::Iec.parse("IEC 61131-3:2013")id = Pubid::Nist.parse("NIST SP 800-53 Rev. 5")Parameters:
string(String) — The identifier to parse
Returns: Identifier object (flavor-specific class)
Raises: ParseError if the identifier cannot be parsed
Identifier Instance Methods
#to_s(**opts)
Render the identifier as a canonical string.
id = Pubid::Iso.parse("ISO 9001:2015")id.to_s # => "ISO 9001:2015"Options (varies by flavor):
:lang— Language for localized output:with_edition— Include edition number
#to_urn
Generate a URN representation.
id.to_urn # => "urn:iso:std:iso:9001"#to_pubid_urn
Generate a pubid-scheme URN — the machine form that always round-trips
(the official #to_urn may be lossy):
id = Pubid::Iso.parse("ISO 9001:2015")id.to_pubid_urn # => "urn:pubid:iso:is:9001:year-2015"Pubid.parse_urn(id.to_pubid_urn).to_hash == id.to_hash # => truePubid.parse_urn(string) / Pubid.parse_pubid_urn(string)
Parse a URN. Pubid.parse_urn detects the namespace and routes —
urn:pubid:… to the shared codec, everything else to the flavor’s URN
parser. Pubid.parse_pubid_urn accepts a pubid-scheme URN and only that;
an official URN raises Pubid::Errors::UrnParseError.
Pubid.to_slug(source) / Pubid.from_slug(string)
The slug form — the pubid-scheme URN as an HTTP path
(iso/is/9001/year-2015). Bijective: from_slug rebuilds the exact URN,
so a slug round-trips like its URN.
Pubid.to_slug(id) # => "iso/is/9001/year-2015"Pubid.from_slug("iso/is/9001/year-2015") # => ISO 9001:2015See The pubid URN Scheme for the grammar and the round-trip contract.
#to_hash
Serialize to a Hash — the canonical form Pubid.from_hash rebuilds from
(reading the _type key):
id.to_hash# => { "_type" => "pubid:iso:international-standard", "number" => "9001", "year" => "2015" }#to_json
Serialize to JSON.
id.to_json # => '{"_type":"pubid:iso:international-standard","number":"9001","year":"2015"}'Identifier Relations
Predicates that relate two identifiers. Each returns true or false; a
predicate that does not apply returns false rather than raising. Wrappers
(supplement bases, consolidated collections) compare through the document
they wrap.
| Predicate | True when |
|---|---|
supplement_of? |
self is a supplement (amendment, corrigendum, …) whose base is the other identifier |
has_supplement? |
the other identifier is a supplement of self |
dated_version_of? |
both are the same document differing only in date |
sibling_of? |
same document, different part/subpart |
edition_of? |
both are editions of the same document |
includes? |
self is an “all parts” collection covering the other identifier |
draft_of? |
self is a draft of the published identifier |
related_to? |
any of the above |
Two rules govern supplement composites such as
BS 7273-4:2015+A1:2021 (the document BS 7273-4:2015 read together with
its amendment):
- The supplement year is identity-bearing. An amendment is published
once under its ordinal —
+A1:2022does not exist — so the year is never ignored when matching dates. - Composites of one base document are editions of each other — they are the consolidated document’s successive states. A composite and its bare base are not editions: the series is supersession, not an edition-year relationship, and the amendment supplements the base without superseding it.
a1 = Pubid::Bsi.parse("BS 7273-4:2015+A1:2021")a2 = Pubid::Bsi.parse("BS 7273-4:2015+A2:2023")bare = Pubid::Bsi.parse("BS 7273-4:2015")
a1.edition_of?(a2) # => true — prior edition of the consolidated documenta1.dated_version_of?(a2) # => false — differs by incorporation, not just datea1.edition_of?(bare) # => false — supersession series, not edition-year
amd = Pubid::Iso.parse("ISO 9001:2015/Amd 1:2020")base = Pubid::Iso.parse("ISO 9001:2015")amd.supplement_of?(base) # => true — and not edition_of?Common Attributes
Most identifier objects expose these attributes:
| Attribute | Type | Description |
|---|---|---|
publisher |
String | Publisher code |
number |
String | Document number |
part |
String | Part number |
year |
Integer | Publication year |
edition |
Integer | Edition number |
stage |
Stage | Development stage |
language |
String | Language code |
type |
Type | Document type |
Flavor-Specific Classes
Each flavor has its own identifier classes under Pubid::{Flavor}::Identifiers::*.
For example, ISO has:
Pubid::Iso::Identifiers::InternationalStandardPubid::Iso::Identifiers::TechnicalReportPubid::Iso::Identifiers::Amendment- etc.
Full Reference (generated)
The complete, generated references — every public entry point with its signature and docstring — are built from the sources themselves and cannot drift from the code (CI regenerates them on every change):