Class: Pubid::Oiml::SingleIdentifier
Constant Summary
Constants inherited
from Identifier
Identifier::OIML_TYPE_MAP
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#code_for(model) ⇒ Object
-
#edition_portion ⇒ Object
-
#emit_kv(doc, key, value) ⇒ Object
-
#number_from_kv(model, value) ⇒ Object
-
#number_to_kv(model, doc) ⇒ Object
--- code components flattened to top-level keys ---.
-
#part_from_kv(model, value) ⇒ Object
-
#part_to_kv(model, doc) ⇒ Object
-
#space_suffix_from_kv(model, value) ⇒ Object
-
#space_suffix_to_kv(model, doc) ⇒ Object
-
#subpart_from_kv(model, value) ⇒ Object
-
#subpart_to_kv(model, doc) ⇒ Object
-
#suffix_from_kv(model, value) ⇒ Object
-
#suffix_to_kv(model, doc) ⇒ Object
-
#to_s(format: nil, **opts) ⇒ Object
-
#type ⇒ Object
Type is determined by the subclass.
-
#type_string ⇒ Object
Subclasses override this.
-
#year_from_kv(model, value) ⇒ Object
-
#year_to_kv(model, doc) ⇒ Object
--- date flattened to a top-level year ---.
Methods inherited from Identifier
from_hash, #to_urn
Instance Attribute Details
Returns the value of attribute requested_format.
76
77
78
|
# File 'lib/pubid/oiml/single_identifier.rb', line 76
def requested_format
@requested_format
end
|
Instance Method Details
#code_for(model) ⇒ Object
72
73
74
|
# File 'lib/pubid/oiml/single_identifier.rb', line 72
def code_for(model)
model.code ||= Components::Code.new
end
|
#edition_portion ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/pubid/oiml/single_identifier.rb', line 89
def edition_portion
if edition && date
"#{edition} Edition #{date.year}"
elsif date
"Edition #{date.year}"
else
edition
end
end
|
#emit_kv(doc, key, value) ⇒ Object
66
67
68
69
70
|
# File 'lib/pubid/oiml/single_identifier.rb', line 66
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
|
#number_from_kv(model, value) ⇒ Object
39
|
# File 'lib/pubid/oiml/single_identifier.rb', line 39
def number_from_kv(model, value) = code_for(model).number = value.to_s
|
#number_to_kv(model, doc) ⇒ Object
--- code components flattened to top-level keys ---
38
|
# File 'lib/pubid/oiml/single_identifier.rb', line 38
def number_to_kv(model, doc) = emit_kv(doc, "number", model.code&.number)
|
#part_from_kv(model, value) ⇒ Object
41
|
# File 'lib/pubid/oiml/single_identifier.rb', line 41
def part_from_kv(model, value) = code_for(model).part = value.to_s
|
#part_to_kv(model, doc) ⇒ Object
40
|
# File 'lib/pubid/oiml/single_identifier.rb', line 40
def part_to_kv(model, doc) = emit_kv(doc, "part", model.code&.part)
|
#space_suffix_from_kv(model, value) ⇒ Object
55
56
57
|
# File 'lib/pubid/oiml/single_identifier.rb', line 55
def space_suffix_from_kv(model, value)
code_for(model).space_suffix = value
end
|
#space_suffix_to_kv(model, doc) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/pubid/oiml/single_identifier.rb', line 47
def space_suffix_to_kv(model, doc)
return unless model.code&.space_suffix
doc.add_child(
Lutaml::KeyValue::DataModel::Element.new("space_suffix", true),
)
end
|
#subpart_from_kv(model, value) ⇒ Object
43
|
# File 'lib/pubid/oiml/single_identifier.rb', line 43
def subpart_from_kv(model, value) = code_for(model).subpart = value.to_s
|
#subpart_to_kv(model, doc) ⇒ Object
42
|
# File 'lib/pubid/oiml/single_identifier.rb', line 42
def subpart_to_kv(model, doc) = emit_kv(doc, "subpart", model.code&.subpart)
|
#suffix_from_kv(model, value) ⇒ Object
45
|
# File 'lib/pubid/oiml/single_identifier.rb', line 45
def suffix_from_kv(model, value) = code_for(model).suffix = value.to_s
|
#suffix_to_kv(model, doc) ⇒ Object
44
|
# File 'lib/pubid/oiml/single_identifier.rb', line 44
def suffix_to_kv(model, doc) = emit_kv(doc, "suffix", model.code&.suffix)
|
#to_s(format: nil, **opts) ⇒ Object
83
84
85
86
87
|
# File 'lib/pubid/oiml/single_identifier.rb', line 83
def to_s(format: nil, **opts)
@requested_format = format
render(format: :human, **opts)
end
|
#type ⇒ Object
Type is determined by the subclass
79
80
81
|
# File 'lib/pubid/oiml/single_identifier.rb', line 79
def type
type_string
end
|
#type_string ⇒ Object
102
103
104
|
# File 'lib/pubid/oiml/single_identifier.rb', line 102
def type_string
raise NotImplementedError, "Subclasses must implement type_string"
end
|
#year_from_kv(model, value) ⇒ Object
62
63
64
|
# File 'lib/pubid/oiml/single_identifier.rb', line 62
def year_from_kv(model, value)
(model.date ||= Pubid::Components::Date.new).year = value.to_s
end
|
#year_to_kv(model, doc) ⇒ Object
--- date flattened to a top-level year ---
60
|
# File 'lib/pubid/oiml/single_identifier.rb', line 60
def year_to_kv(model, doc) = emit_kv(doc, "year", model.date&.year)
|