Class: Pubid::Calconnect::Identifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Calconnect::Identifier
- Defined in:
- lib/pubid/calconnect/identifier.rb
Overview
Base class for every CalConnect identifier AND the flavor's parse entry
point — mirrors Pubid::Jis::Identifier. Concrete identifiers under
Pubid::Calconnect::Identifiers descend from this class, so a parsed
CalConnect id is an instance of Pubid::Calconnect::Identifier and
relaton-index can pass this class as pubid_class for from_hash/to_hash.
Direct Known Subclasses
Constant Summary collapse
- CALCONNECT_TYPE_MAP =
Polymorphic type map for lutaml::Model key_value (de)serialization, mapping the concrete class's polymorphic_name to its class name so a stored hash rebuilds the correct identifier type via from_hash.
{ "pubid:calconnect:standard" => "Pubid::Calconnect::Identifiers::Standard", }.freeze
- PUBLISHER =
Publisher is always "CC". A plain constant (not a
publishermethod) so it doesn't shadow the inherited lutamlpublisherattribute, which would otherwise fail serialization type validation. "CC"
Instance Attribute Summary collapse
-
#with_publisher ⇒ Object
readonly
Returns the value of attribute with_publisher.
Class Method Summary collapse
-
.parse(identifier) ⇒ Identifier
Parse a CalConnect identifier string into an identifier object.
Instance Method Summary collapse
- #date_for(model) ⇒ Object
-
#date_string ⇒ Object
Render the publication date, e.g.
- #day_from_kv(model, value) ⇒ Object
- #day_to_kv(model, doc) ⇒ Object
- #emit_date_part(doc, key, val) ⇒ Object
- #month_from_kv(model, value) ⇒ Object
- #month_to_kv(model, doc) ⇒ Object
-
#render(format: :human, with_publisher: true, **opts) ⇒ Object
Capture the with_publisher flag on EVERY render call (default true), so it can never leak across calls.
-
#to_s(**opts) ⇒ Object
Basic string representation.
- #year_from_kv(model, value) ⇒ Object
-
#year_to_kv(model, doc) ⇒ Object
--- date serialized flat as year/month/day (mirrors ISO) ---.
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?, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
This class inherits a constructor from Pubid::Identifier
Instance Attribute Details
#with_publisher ⇒ Object (readonly)
Returns the value of attribute with_publisher.
45 46 47 |
# File 'lib/pubid/calconnect/identifier.rb', line 45 def with_publisher @with_publisher end |
Class Method Details
.parse(identifier) ⇒ Identifier
Parse a CalConnect identifier string into an identifier object.
106 107 108 109 110 111 112 113 114 |
# File 'lib/pubid/calconnect/identifier.rb', line 106 def self.parse(identifier) if identifier.length > Pubid::MAX_INPUT_LENGTH raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE end Builder.build(Parser.parse(identifier)) rescue Parslet::ParseFailed => e raise "Failed to parse CalConnect '#{identifier}': #{e.}" end |
Instance Method Details
#date_for(model) ⇒ Object
94 95 96 |
# File 'lib/pubid/calconnect/identifier.rb', line 94 def date_for(model) model.date ||= ::Pubid::Components::Date.new end |
#date_string ⇒ Object
Render the publication date, e.g. "2018" or "2024-07-23". Shared by the renderer and the URN generator so they always agree. Pubid::Components::Date#to_s yields the year alone, or the zero-padded "YYYY-MM-DD" when month/day are present.
51 52 53 |
# File 'lib/pubid/calconnect/identifier.rb', line 51 def date_string date&.to_s end |
#day_from_kv(model, value) ⇒ Object
86 |
# File 'lib/pubid/calconnect/identifier.rb', line 86 def day_from_kv(model, value) = date_for(model).day = value.to_s |
#day_to_kv(model, doc) ⇒ Object
80 81 82 |
# File 'lib/pubid/calconnect/identifier.rb', line 80 def day_to_kv(model, doc) emit_date_part(doc, "day", model.date&.day) end |
#emit_date_part(doc, key, val) ⇒ Object
88 89 90 91 92 |
# File 'lib/pubid/calconnect/identifier.rb', line 88 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
85 |
# File 'lib/pubid/calconnect/identifier.rb', line 85 def month_from_kv(model, value) = date_for(model).month = value.to_s |
#month_to_kv(model, doc) ⇒ Object
76 77 78 |
# File 'lib/pubid/calconnect/identifier.rb', line 76 def month_to_kv(model, doc) emit_date_part(doc, "month", model.date&.month) end |
#render(format: :human, with_publisher: true, **opts) ⇒ Object
Capture the with_publisher flag on EVERY render call (default true), so
it can never leak across calls. The base render only forwards
:with_edition to the renderer, so the flag is threaded via this
per-call instance write (the renderer reads id.with_publisher).
66 67 68 69 |
# File 'lib/pubid/calconnect/identifier.rb', line 66 def render(format: :human, with_publisher: true, **opts) @with_publisher = with_publisher super(format: format, **opts) end |
#to_s(**opts) ⇒ Object
Basic string representation. Delegates to the human renderer. The printed CalConnect id carries the "CC" publisher token by default; pass with_publisher: false to drop it (and the series slash).
58 59 60 |
# File 'lib/pubid/calconnect/identifier.rb', line 58 def to_s(**opts) render(format: :human, **opts) end |
#year_from_kv(model, value) ⇒ Object
84 |
# File 'lib/pubid/calconnect/identifier.rb', line 84 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 (mirrors ISO) ---
72 73 74 |
# File 'lib/pubid/calconnect/identifier.rb', line 72 def year_to_kv(model, doc) emit_date_part(doc, "year", model.date&.year) end |