Class: Pubid::Oasis::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/oasis/builder.rb

Overview

Turns the parse tree into an Identifiers::Standard: stores the slug verbatim in original, then performs a best-effort, ORDER-INDEPENDENT decomposition into spec / version / stage / part / label.

Decomposition splits original on "-" and classifies each whole fragment (so a stage-like substring inside a spec name — e.g. "CSDL" — is never mistaken for a stage). spec is the run of leading name fragments before the first recognized fragment; version/stage/part are the first fragment of each recognized kind; label is any name fragment appearing after the first recognized one. Anything the classifier cannot place stays only in original, so the printed form always round-trips.

Constant Summary collapse

VERSION_RE =

A fragment is a version when it is v?N(.N)+ (e.g. "3.0", "v1.2.1", "V1.0"). Bare integers are deliberately NOT versions (too ambiguous with spec-name tokens).

/\Av?\d+(?:\.\d+)+\z/i
STAGE_RE =

OASIS approval-stage tokens (+ optional revision digits). Longest-first so shared prefixes classify correctly (CSPRD/CSD before CS, COS before CS/OS).

/\A(?:CSPRD|CSD|COS|CS|WD|OS|PS|PRD|CD|Errata)\d*\z/
PART_RE =

Part tokens across the three observed spellings, plus bare "Pt"/"P".

/\A(?:Part|Pt|part|P)\d*\z/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed_data) ⇒ Object



28
29
30
# File 'lib/pubid/oasis/builder.rb', line 28

def self.build(parsed_data)
  new.build(parsed_data)
end

Instance Method Details

#build(data) ⇒ Object



32
33
34
35
# File 'lib/pubid/oasis/builder.rb', line 32

def build(data)
  original = data[:original].to_s
  Identifiers::Standard.new(original: original, **decompose(original))
end