Class: Pubid::Amca::Identifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Amca::Identifier
show all
- Defined in:
- lib/pubid/amca/identifiers/base.rb
Overview
Base identifier class for AMCA identifiers. Canonical name
Pubid::Amca::Identifier (Identifiers::Base is a back-compat alias); common
functionality for all AMCA identifier types.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, from_hash, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #render, #resolve_urn_generator, #root, #to_hash, #to_mr_string, #to_s, #to_supplement_s, #urn_supplement_type, #urn_type_code, #year
Class Method Details
.parse(identifier) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/pubid/amca/identifiers/base.rb', line 10
def self.parse(identifier)
parsed = Parser.parse(identifier)
Builder.build(parsed)
rescue Parslet::ParseFailed => e
raise "Failed to parse ACMA identifier '#{identifier}': #{e.message}"
end
|
Instance Method Details
#code_from_kv(model, value) ⇒ Object
53
54
55
|
# File 'lib/pubid/amca/identifiers/base.rb', line 53
def code_from_kv(model, value)
model.code = ::Pubid::Components::Code.new(value: value.to_s)
end
|
#code_to_kv(model, doc) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/pubid/amca/identifiers/base.rb', line 46
def code_to_kv(model, doc)
v = model.code.is_a?(::Pubid::Components::Code) ? model.code.value : model.code
return if v.nil? || v.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new("code", v.to_s))
end
|
#year_from_kv(model, value) ⇒ Object
64
65
66
|
# File 'lib/pubid/amca/identifiers/base.rb', line 64
def year_from_kv(model, value)
model.year = ::Pubid::Components::Date.new(year: value.to_s)
end
|
#year_to_kv(model, doc) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/pubid/amca/identifiers/base.rb', line 57
def year_to_kv(model, doc)
y = model.year.is_a?(::Pubid::Components::Date) ? model.year.year : model.year
return if y.nil? || y.to_s.empty?
doc.add_child(Lutaml::KeyValue::DataModel::Element.new("year", y.to_s))
end
|