Class: Pubid::Iec::Renderer::Urn

Inherits:
Core::Renderer::Urn
  • Object
show all
Defined in:
lib/pubid/iec/renderer/urn.rb

Direct Known Subclasses

TrfUrn, WorkingDocumentUrn

Constant Summary collapse

STAGES =
{ ACD: 20.99,
           ACDV: 30.99,
           ADTR: 40.99,
           ADTS: 40.99,
           AFDIS: 40.99,
           APUB: 50.99,
           BPUB: 60,
           CAN: 30.98,
           CCDV: 40.20,
           CD: 30.20,
           CDISH: 50.20,
           CDM: 30.60,
           CDPAS: 50.20,
           CDTR: 50.20,
           CDTS: 50.20,
           CDVM: 40.91,
           CFDIS: 50.20,
           DECDISH: 50.00,
           DECFDIS: 50.00,
           DECPUB: 60.00,
           DEL: 10.98,
           DELPUB: 99.60,
           DTRM: 50.92,
           DTSM: 50.92,
           MERGED: 30.97,
           NCDV: 40.91,
           NDTR: 50.92,
           NDTS: 50.92,
           NFDIS: 50.92,
           PCC: 30.60,
           PNW: 10.20,
           PPUB: 60.60,
           PRVC: 40.60,
           PRVD: 50.60,
           PRVDISH: 50.60,
           PRVDPAS: 50.60,
           PRVDTR: 50.60,
           PRVDTS: 50.60,
           PRVN: 10.60,
           PWI: 0,
           RDISH: 50.00,
           RFDIS: 50.00,
           RPUB: 60.00,
           SPLIT: 30.96,
           TCDV: 40.00,
           TDISH: 50.00,
           TDTR: 50.00,
           TDTS: 50.00,
           TPUB: 60.00,
           WPUB: 95.99
}.freeze

Instance Method Summary collapse

Instance Method Details

#render(with_date: true, with_language_code: :iso, annotated: false, **args) ⇒ Object



101
102
103
104
105
# File 'lib/pubid/iec/renderer/urn.rb', line 101

def render(with_date: true, with_language_code: :iso, annotated: false, **args)
  render_base_identifier(**args.merge(
    with_date: with_date, with_language_code: with_language_code, annotated: annotated,
  ))
end

#render_amendments(amendments, _opts, params) ⇒ Object

Amendments render as "markeramd:number". The marker is ":plus:" when the base is a consolidation (CSV/CMV) — the amendment is merged into the consolidated document — otherwise "::".



150
151
152
153
154
155
156
157
# File 'lib/pubid/iec/renderer/urn.rb', line 150

def render_amendments(amendments, _opts, params)
  marker = consolidated_deliverable?(params) ? ":plus:" : "::"
  Array(amendments).map do |amendment|
    s = "#{marker}amd:#{amendment.number}"
    s += ":#{amendment.year}" if amendment.year
    s
  end.join
end

#render_conjuction_part(conjuction_parts, _opts, _params) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/pubid/iec/renderer/urn.rb', line 131

def render_conjuction_part(conjuction_parts, _opts, _params)
  if conjuction_parts.is_a?(Array)
    conjuction_parts.map(&:to_i).sort.map { |conjuction_part| ",#{conjuction_part}" }.join
  else
    ",#{conjuction_parts}"
  end
end

#render_copublisher(copublisher, _opts, _params) ⇒ Object



173
174
175
# File 'lib/pubid/iec/renderer/urn.rb', line 173

def render_copublisher(copublisher, _opts, _params)
  "-" + Array(copublisher).map { |c| c.to_s.downcase }.join("-")
end

#render_corrigendums(corrigendums, _opts, _params) ⇒ Object

Corrigenda always use the "::" relation-marker (they are separate corrections, never merged into a consolidation).



161
162
163
164
165
166
167
# File 'lib/pubid/iec/renderer/urn.rb', line 161

def render_corrigendums(corrigendums, _opts, _params)
  Array(corrigendums).map do |corrigendum|
    s = "::cor:#{corrigendum.number}"
    s += ":#{corrigendum.year}" if corrigendum.year
    s
  end.join
end

#render_fragment(fragment, _opts, _params) ⇒ Object



119
120
121
# File 'lib/pubid/iec/renderer/urn.rb', line 119

def render_fragment(fragment, _opts, _params)
  ":frag:#{fragment}"
end

#render_identifier(params) ⇒ Object

Renders the ABNF-canonical IEC URN (ground truth in relaton-data-iec):

urn:iec:std:{pub}[-{copub}][:{type}]:{number}[-{part}][,{conj}]
  :{date}:{stage}:{deliverable}:{language}{adjuncts}[{fragment}]

The four positional slots after the number/part are always colon- separated even when empty. Amendments/corrigenda follow the language slot with a "::" (or ":plus:" for a consolidated amendment) relation- marker; see #render_amendments / #render_corrigendums.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/pubid/iec/renderer/urn.rb', line 64

def render_identifier(params)
  result = "urn:iec:std:#{params[:publisher]}#{params[:copublisher]}" \
           "#{params[:type]}:#{params[:number]}" \
           "#{params[:part]}#{params[:conjuction_part]}"

  # Positional slots — always colon-separated even when empty.
  result += ":#{strip_leading_colon(params[:year])}"

  # Stage slot (deliverable/vap is no longer folded in here; it has its
  # own canonical deliverable slot below).
  stage_value = [params[:stage], params[:urn_stage],
                 params[:corrigendum_stage], params[:iteration],
                 params[:version], params[:part_version]].map(&:to_s).join
  result += ":#{strip_leading_colon(stage_value)}"

  # Deliverable slot: "ser" (all parts), a deliverable code (csv/rlv/…),
  # or the edition (ed-N) when neither is present.
  deliverable = deliverable_slot(params)
  result += ":#{deliverable}"

  # Language slot. A bare (undated, stage/language/adjunct-less) all-parts
  # series omits the trailing empty language slot, matching the canonical
  # relaton-data-iec form: urn:iec:std:iec:80000:::ser (not ...:ser:). A
  # dated series (...:2026::ser:) or a deliverable (...::rlv:) keeps it.
  unless bare_series?(deliverable, stage_value, params)
    result += ":#{strip_leading_colon(params[:language].to_s)}"
  end

  # Adjuncts (amendments/corrigenda) with the relation-marker, then any
  # fragment.
  result += params[:amendments].to_s
  result += params[:corrigendums].to_s
  result += params[:fragment].to_s

  result
end

#render_language(language, _opts, _params) ⇒ Object



169
170
171
# File 'lib/pubid/iec/renderer/urn.rb', line 169

def render_language(language, _opts, _params)
  ":" + (language.is_a?(Array) ? language.join("-") : language)
end

#render_number(number, _opts, _params) ⇒ Object



111
112
113
# File 'lib/pubid/iec/renderer/urn.rb', line 111

def render_number(number, _opts, _params)
  number.to_s.downcase
end

#render_part(part, _opts, _params) ⇒ Object



107
108
109
# File 'lib/pubid/iec/renderer/urn.rb', line 107

def render_part(part, _opts, _params)
  "-#{part}"
end

#render_part_version(part_version, _opts, _params) ⇒ Object



127
128
129
# File 'lib/pubid/iec/renderer/urn.rb', line 127

def render_part_version(part_version, _opts, _params)
  ":v#{part_version}"
end

#render_stage(stage, _opts, params) ⇒ Object



139
140
141
# File 'lib/pubid/iec/renderer/urn.rb', line 139

def render_stage(stage, _opts, params)
  ":stage-#{sprintf('%s', stage.to_s(:urn))}"
end

#render_type(type, _, _) ⇒ Object



143
144
145
# File 'lib/pubid/iec/renderer/urn.rb', line 143

def render_type(type, _, _)
  ":#{type.downcase}"
end

#render_vap(vap, _opts, _params) ⇒ Object



115
116
117
# File 'lib/pubid/iec/renderer/urn.rb', line 115

def render_vap(vap, _opts, _params)
  ":#{vap.map(&:downcase).join('-')}"
end

#render_version(version, _opts, _params) ⇒ Object



123
124
125
# File 'lib/pubid/iec/renderer/urn.rb', line 123

def render_version(version, _opts, _params)
  ":v#{version}"
end