Class: Pubid::Jcgm::SingleIdentifier
Class Method Summary
collapse
Instance Method Summary
collapse
-
#build_code(value) ⇒ Object
-
#date_for(model) ⇒ Object
-
#day_from_kv(model, value) ⇒ Object
-
#day_to_kv(model, doc) ⇒ Object
-
#emit_kv(doc, key, value) ⇒ Object
-
#language_portion ⇒ Object
-
#month_from_kv(model, value) ⇒ Object
-
#month_to_kv(model, doc) ⇒ Object
-
#number_from_kv(model, value) ⇒ Object
-
#number_portion ⇒ Object
-
#number_to_kv(model, doc) ⇒ Object
--- number (Code) flattened to a bare string ---.
-
#publisher_portion ⇒ Object
-
#stage ⇒ Object
-
#type ⇒ Object
type and stage are derived from typed_stage, never stored — so the doctype (fixed by the class / _type) is not carried in the hash.
-
#year_from_kv(model, value) ⇒ Object
-
#year_to_kv(model, doc) ⇒ Object
--- date flattened to top-level year/month/day scalars ---.
Methods inherited from Identifier
parse
Methods inherited from Identifier
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
.default_publisher ⇒ Object
The publisher implied when none is serialized — always JCGM.
.published_typed_stage ⇒ Object
The class's published typed_stage (canonical surface form). Each JCGM
class registers exactly one, all :published; _type fixes the class,
so an omitted typed_stage reconstructs deterministically on from_hash.
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 40
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
#build_code(value) ⇒ Object
65
66
67
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 65
def build_code(value)
Pubid::Components::Code.new(value: value.to_s)
end
|
#date_for(model) ⇒ Object
83
84
85
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 83
def date_for(model)
model.date ||= Pubid::Components::Date.new
end
|
#day_from_kv(model, value) ⇒ Object
75
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 75
def day_from_kv(model, value) = date_for(model).day = value.to_s
|
#day_to_kv(model, doc) ⇒ Object
72
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 72
def day_to_kv(model, doc) = emit_kv(doc, "day", model.date&.day)
|
#emit_kv(doc, key, value) ⇒ Object
77
78
79
80
81
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 77
def emit_kv(doc, key, value)
return if value.nil? || value.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new(key, value.to_s))
end
|
#language_portion ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 98
def language_portion
return "" unless languages&.any?
[
"(",
languages.map(&:original_code).join("/"),
")",
].join
end
|
#month_from_kv(model, value) ⇒ Object
74
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 74
def month_from_kv(model, value) = date_for(model).month = value.to_s
|
#month_to_kv(model, doc) ⇒ Object
71
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 71
def month_to_kv(model, doc) = emit_kv(doc, "month", model.date&.month)
|
#number_from_kv(model, value) ⇒ Object
63
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 63
def number_from_kv(model, value) = model.number = build_code(value)
|
#number_portion ⇒ Object
91
92
93
94
95
96
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 91
def number_portion
parts = []
parts << number.value if number
parts << ":#{date.year}" if date
parts.join
end
|
#number_to_kv(model, doc) ⇒ Object
--- number (Code) flattened to a bare string ---
62
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 62
def number_to_kv(model, doc) = emit_kv(doc, "number", model.number&.value)
|
#publisher_portion ⇒ Object
87
88
89
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 87
def publisher_portion
publisher.to_s
end
|
#stage ⇒ Object
57
58
59
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 57
def stage
typed_stage&.to_stage
end
|
#type ⇒ Object
type and stage are derived from typed_stage, never stored — so the
doctype (fixed by the class / _type) is not carried in the hash.
53
54
55
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 53
def type
typed_stage&.to_type
end
|
#year_from_kv(model, value) ⇒ Object
73
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 73
def year_from_kv(model, value) = date_for(model).year = value.to_s
|
#year_to_kv(model, doc) ⇒ Object
--- date flattened to top-level year/month/day scalars ---
70
|
# File 'lib/pubid/jcgm/single_identifier.rb', line 70
def year_to_kv(model, doc) = emit_kv(doc, "year", model.date&.year)
|