Class: Pubid::Iso::Identifier
Constant Summary
collapse
- ISO_TYPE_MAP =
Polymorphic type map for lutaml::Model key_value serialization
Maps polymorphic_name → class name for deserialization
Validated by spec to stay in sync with identifier_types
{
"pubid:iso:international-standard" => "Pubid::Iso::Identifiers::InternationalStandard",
"pubid:iso:international-standardized-profile" => "Pubid::Iso::Identifiers::InternationalStandardizedProfile",
"pubid:iso:international-workshop-agreement" => "Pubid::Iso::Identifiers::InternationalWorkshopAgreement",
"pubid:iso:technical-report" => "Pubid::Iso::Identifiers::TechnicalReport",
"pubid:iso:technical-specification" => "Pubid::Iso::Identifiers::TechnicalSpecification",
"pubid:iso:pas" => "Pubid::Iso::Identifiers::Pas",
"pubid:iso:guide" => "Pubid::Iso::Identifiers::Guide",
"pubid:iso:recommendation" => "Pubid::Iso::Identifiers::Recommendation",
"pubid:iso:amendment" => "Pubid::Iso::Identifiers::Amendment",
"pubid:iso:corrigendum" => "Pubid::Iso::Identifiers::Corrigendum",
"pubid:iso:supplement" => "Pubid::Iso::Identifiers::Supplement",
"pubid:iso:addendum" => "Pubid::Iso::Identifiers::Addendum",
"pubid:iso:extract" => "Pubid::Iso::Identifiers::Extract",
"pubid:iso:directives" => "Pubid::Iso::Identifiers::Directives",
"pubid:iso:directives-supplement" => "Pubid::Iso::Identifiers::DirectivesSupplement",
"pubid:iso:data" => "Pubid::Iso::Identifiers::Data",
"pubid:iso:tc-document" => "Pubid::Iso::Identifiers::TcDocument",
"pubid:iso:technology-trends-assessments" => "Pubid::Iso::Identifiers::TechnologyTrendsAssessments",
"pubid:iso:bundled-identifier" => "Pubid::Iso::BundledIdentifier",
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
-
#all_parts_from_kv(model, value) ⇒ Object
-
#all_parts_to_kv(model, doc) ⇒ Object
-
#build_code(value) ⇒ Object
-
#copublishers_from_kv(model, value) ⇒ Object
-
#copublishers_to_kv(model, doc) ⇒ Object
-
#date_for(model) ⇒ Object
-
#day_from_kv(model, value) ⇒ Object
-
#day_to_kv(model, doc) ⇒ Object
-
#emit_code(doc, key, code) ⇒ Object
-
#emit_date_part(doc, key, val) ⇒ Object
-
#month_from_kv(model, value) ⇒ Object
-
#month_to_kv(model, doc) ⇒ Object
-
#number_from_kv(model, value) ⇒ Object
-
#number_to_kv(model, doc) ⇒ Object
--- Code components <-> plain string ---.
-
#part_from_kv(model, value) ⇒ Object
-
#part_to_kv(model, doc) ⇒ Object
-
#publisher_for(model) ⇒ Object
-
#publisher_from_kv(model, value) ⇒ Object
-
#publisher_to_kv(model, doc) ⇒ Object
--- publisher: primary only when non-default; copublishers as a list ---.
-
#stage ⇒ Object
-
#stage_from_kv(model, value) ⇒ Object
Resolve the typed-stage code back to the full TypedStage within this identifier's class, then derive type/stage from it.
-
#stage_iteration_from_kv(model, value) ⇒ Object
-
#stage_iteration_to_kv(model, doc) ⇒ Object
-
#stage_to_kv(model, doc) ⇒ Object
Serialize typed_stage as just its unique code (e.g. "is", "dis", "committee_draft_amd").
-
#subpart_from_kv(model, value) ⇒ Object
-
#subpart_to_kv(model, doc) ⇒ Object
-
#type ⇒ Object
type and stage are derived from typed_stage, never stored — so the doctype (fixed by the class / _type) can't be lost when "stage" is omitted for the published default.
-
#undated_from_kv(model, value) ⇒ Object
-
#undated_to_kv(model, doc) ⇒ Object
--- date undated flag (ISO/IEC undated reference, e.g. ISO 16634:--) --- The false default is omitted; only the meaningful true round-trips via to_hash / from_hash.
-
#with_harmonized_stage(harmonized_code) ⇒ Object
Return a copy with the lifecycle stage set from an ISO harmonized stage code (e.g. "90.92").
-
#year_from_kv(model, value) ⇒ Object
-
#year_to_kv(model, doc) ⇒ Object
--- date serialized flat as year/month/day ---.
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_s, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Class Method Details
.build_type_map ⇒ Object
Build type map from Pubid::Iso.identifier_types for validation
97
98
99
100
101
|
# File 'lib/pubid/iso/identifier.rb', line 97
def self.build_type_map
Pubid::Iso.identifier_types.to_h do |klass|
[klass.polymorphic_name, klass.name]
end
end
|
.default_publisher ⇒ Object
The publisher implied when none is serialized. ISO for most types;
publisher-less types (IWA) override this to nil.
.parse(string, format: :auto) ⇒ Object
.published_typed_stage ⇒ Object
The class's published typed_stage (canonical surface form), or nil for
types with no stages (e.g. TC documents).
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/pubid/iso/identifier.rb', line 28
def self.published_typed_stage
return nil unless const_defined?(:TYPED_STAGES)
ts = self::TYPED_STAGES.find { |t| t.stage_code.to_s == "published" }
return nil unless ts
ts = ts.dup
ts.original_abbr = ts.canonical_abbreviation
ts
end
|
Instance Method Details
#all_parts_from_kv(model, value) ⇒ Object
147
148
149
|
# File 'lib/pubid/iso/identifier.rb', line 147
def all_parts_from_kv(model, value)
model.all_parts = value
end
|
#all_parts_to_kv(model, doc) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/pubid/iso/identifier.rb', line 139
def all_parts_to_kv(model, doc)
return unless model.all_parts
doc.add_child(
Lutaml::KeyValue::DataModel::Element.new("all_parts", true),
)
end
|
#build_code(value) ⇒ Object
211
212
213
|
# File 'lib/pubid/iso/identifier.rb', line 211
def build_code(value)
::Pubid::Iso::Components::Code.new(value: value.to_s)
end
|
#copublishers_from_kv(model, value) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/pubid/iso/identifier.rb', line 267
def copublishers_from_kv(model, value)
list = Array(value).map(&:to_s)
return unless list.any?
publisher_for(model).copublisher = list
model.copublishers = list.map do |cp|
::Pubid::Iso::Components::Publisher.new(publisher: cp)
end
end
|
#copublishers_to_kv(model, doc) ⇒ Object
258
259
260
261
262
263
264
265
|
# File 'lib/pubid/iso/identifier.rb', line 258
def copublishers_to_kv(model, doc)
cp = model.publisher&.copublisher
return unless cp&.any?
doc.add_child(
Lutaml::KeyValue::DataModel::Element.new("copublishers", cp.map(&:to_s)),
)
end
|
#date_for(model) ⇒ Object
242
243
244
|
# File 'lib/pubid/iso/identifier.rb', line 242
def date_for(model)
model.date ||= ::Pubid::Components::Date.new
end
|
#day_from_kv(model, value) ⇒ Object
221
|
# File 'lib/pubid/iso/identifier.rb', line 221
def day_from_kv(model, value) = date_for(model).day = value.to_s
|
#day_to_kv(model, doc) ⇒ Object
220
|
# File 'lib/pubid/iso/identifier.rb', line 220
def day_to_kv(model, doc) = emit_date_part(doc, "day", model.date&.day)
|
#emit_code(doc, key, code) ⇒ Object
204
205
206
207
208
209
|
# File 'lib/pubid/iso/identifier.rb', line 204
def emit_code(doc, key, code)
v = code.is_a?(::Pubid::Components::Code) ? code.value : code
return if v.nil? || v.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new(key, v.to_s))
end
|
#emit_date_part(doc, key, val) ⇒ Object
236
237
238
239
240
|
# File 'lib/pubid/iso/identifier.rb', line 236
def emit_date_part(doc, key, val)
return if val.nil? || val.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new(key, val.to_s))
end
|
#month_from_kv(model, value) ⇒ Object
219
|
# File 'lib/pubid/iso/identifier.rb', line 219
def month_from_kv(model, value) = date_for(model).month = value.to_s
|
#month_to_kv(model, doc) ⇒ Object
218
|
# File 'lib/pubid/iso/identifier.rb', line 218
def month_to_kv(model, doc) = emit_date_part(doc, "month", model.date&.month)
|
#number_from_kv(model, value) ⇒ Object
185
|
# File 'lib/pubid/iso/identifier.rb', line 185
def number_from_kv(model, value) = model.number = build_code(value)
|
#number_to_kv(model, doc) ⇒ Object
--- Code components <-> plain string ---
184
|
# File 'lib/pubid/iso/identifier.rb', line 184
def number_to_kv(model, doc) = emit_code(doc, "number", model.number)
|
#part_from_kv(model, value) ⇒ Object
187
|
# File 'lib/pubid/iso/identifier.rb', line 187
def part_from_kv(model, value) = model.part = build_code(value)
|
#part_to_kv(model, doc) ⇒ Object
186
|
# File 'lib/pubid/iso/identifier.rb', line 186
def part_to_kv(model, doc) = emit_code(doc, "part", model.part)
|
#publisher_for(model) ⇒ Object
281
282
283
|
# File 'lib/pubid/iso/identifier.rb', line 281
def publisher_for(model)
model.publisher ||= ::Pubid::Iso::Components::Publisher.new
end
|
#publisher_from_kv(model, value) ⇒ Object
254
255
256
|
# File 'lib/pubid/iso/identifier.rb', line 254
def publisher_from_kv(model, value)
publisher_for(model).publisher = value.to_s
end
|
#publisher_to_kv(model, doc) ⇒ Object
--- publisher: primary only when non-default; copublishers as a list ---
247
248
249
250
251
252
|
# File 'lib/pubid/iso/identifier.rb', line 247
def publisher_to_kv(model, doc)
pub = model.publisher&.publisher
return if pub.nil? || pub == model.class.default_publisher&.publisher
doc.add_child(Lutaml::KeyValue::DataModel::Element.new("publisher", pub))
end
|
#stage ⇒ Object
46
47
48
|
# File 'lib/pubid/iso/identifier.rb', line 46
def stage
typed_stage&.to_stage
end
|
#stage_from_kv(model, value) ⇒ Object
Resolve the typed-stage code back to the full TypedStage within this
identifier's class, then derive type/stage from it.
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/pubid/iso/identifier.rb', line 166
def stage_from_kv(model, value)
return if value.nil? || value.to_s.empty?
ts = (model.class.const_defined?(:TYPED_STAGES) &&
model.class::TYPED_STAGES.find { |t| t.code.to_s == value.to_s }) ||
Pubid::Iso::Scheme.locate_typed_stage_by_code(value)
return unless ts
ts = ts.dup
ts.original_abbr = ts.canonical_abbreviation
model.typed_stage = ts
end
|
#stage_iteration_from_kv(model, value) ⇒ Object
200
201
202
|
# File 'lib/pubid/iso/identifier.rb', line 200
def stage_iteration_from_kv(model, value)
model.stage_iteration = ::Pubid::Components::Iteration.new(number: value.to_s)
end
|
#stage_iteration_to_kv(model, doc) ⇒ Object
191
192
193
194
195
196
197
198
|
# File 'lib/pubid/iso/identifier.rb', line 191
def stage_iteration_to_kv(model, doc)
iter = model.stage_iteration
v = iter.is_a?(::Pubid::Components::Iteration) ? iter.number : iter
return if v.nil? || v.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new("stage_iteration",
v.to_s))
end
|
#stage_to_kv(model, doc) ⇒ Object
Serialize typed_stage as just its unique code (e.g. "is", "dis",
"committee_draft_amd"). type/stage are recomputed from it on load.
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/pubid/iso/identifier.rb', line 153
def stage_to_kv(model, doc)
ts = model.typed_stage
return unless ts&.code
return if ts.stage_code.to_s == "published"
doc.add_child(
Lutaml::KeyValue::DataModel::Element.new("stage", ts.code.to_s),
)
end
|
#subpart_from_kv(model, value) ⇒ Object
189
|
# File 'lib/pubid/iso/identifier.rb', line 189
def subpart_from_kv(model, value) = model.subpart = build_code(value)
|
#subpart_to_kv(model, doc) ⇒ Object
188
|
# File 'lib/pubid/iso/identifier.rb', line 188
def subpart_to_kv(model, doc) = emit_code(doc, "subpart", model.subpart)
|
#type ⇒ Object
type and stage are derived from typed_stage, never stored — so the
doctype (fixed by the class / _type) can't be lost when "stage" is
omitted for the published default.
42
43
44
|
# File 'lib/pubid/iso/identifier.rb', line 42
def type
typed_stage&.to_type
end
|
#undated_from_kv(model, value) ⇒ Object
232
233
234
|
# File 'lib/pubid/iso/identifier.rb', line 232
def undated_from_kv(model, value)
date_for(model).undated = value.to_s == "true"
end
|
#undated_to_kv(model, doc) ⇒ Object
--- date undated flag (ISO/IEC undated reference, e.g. ISO 16634:--) ---
The false default is omitted; only the meaningful true round-trips
via to_hash / from_hash.
226
227
228
229
230
|
# File 'lib/pubid/iso/identifier.rb', line 226
def undated_to_kv(model, doc)
return unless model.date&.undated?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new("undated", true))
end
|
#with_harmonized_stage(harmonized_code) ⇒ Object
Return a copy with the lifecycle stage set from an ISO harmonized stage
code (e.g. "90.92"). typed_stage is the single source of truth, so this
is all that is needed to surface the stage in #to_s and #to_urn. Returns
an unchanged copy if the code is not recognised.
54
55
56
57
|
# File 'lib/pubid/iso/identifier.rb', line 54
def with_harmonized_stage(harmonized_code)
ts = Pubid::Iso.locate_stage_by_harmonized_code(harmonized_code)
ts ? dup.tap { |id| id.typed_stage = ts } : dup
end
|
#year_from_kv(model, value) ⇒ Object
217
|
# File 'lib/pubid/iso/identifier.rb', line 217
def year_from_kv(model, value) = date_for(model).year = value.to_s
|
#year_to_kv(model, doc) ⇒ Object
--- date serialized flat as year/month/day ---
216
|
# File 'lib/pubid/iso/identifier.rb', line 216
def year_to_kv(model, doc) = emit_date_part(doc, "year", model.date&.year)
|