Class: Pubid::W3c::Builder

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

Overview

Turns the parse tree into a concrete identifier: picks the class from the leading maturity token and splits the captured remainder into code + date.

Constant Summary collapse

TYPE_CLASSES =

Maturity token -> concrete identifier class name (resolved lazily so the Identifiers namespace need not be loaded at class-definition time).

{
  "NOTE" => "Note",
  "DNOTE" => "DraftNote",
  "WD" => "WorkingDraft",
  "CR" => "CandidateRecommendation",
  "CRD" => "CandidateRecommendationDraft",
  "REC" => "Recommendation",
  "PR" => "ProposedRecommendation",
  "PER" => "ProposedEditedRecommendation",
  "SPSD" => "SupersededRecommendation",
  "OBSL" => "ObsoleteRecommendation",
}.freeze
DATE_RE =

A trailing "-" group is the date only when the digit run is exactly 8 (YYYYMMDD), 6 (legacy YYMMDD) or 4 (legacy MMDD) wide. No real W3C code ends in such a run, so this never mis-splits a code that merely ends in a short digit run (e.g. "url-1", "ATAG10").

/\A(.+)-(\d{8}|\d{6}|\d{4})\z/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(parsed_data) ⇒ Object



29
30
31
# File 'lib/pubid/w3c/builder.rb', line 29

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

Instance Method Details

#build(data) ⇒ Object



33
34
35
36
# File 'lib/pubid/w3c/builder.rb', line 33

def build(data)
  code, date = split_date(data[:rest].to_s)
  klass_for(data[:type]&.to_s).new(code: code, date: date)
end