Class: Pubid::Jcgm::SingleIdentifier

Inherits:
Identifier show all
Defined in:
lib/pubid/jcgm/single_identifier.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.default_publisherObject

The publisher implied when none is serialized — always JCGM.



33
34
35
# File 'lib/pubid/jcgm/single_identifier.rb', line 33

def self.default_publisher
  Jcgm::Components::Publisher.new(publisher: Jcgm::PREFIXES.first)
end

.published_typed_stageObject

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_portionObject



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_portionObject



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_portionObject



87
88
89
# File 'lib/pubid/jcgm/single_identifier.rb', line 87

def publisher_portion
  publisher.to_s
end

#stageObject



57
58
59
# File 'lib/pubid/jcgm/single_identifier.rb', line 57

def stage
  typed_stage&.to_stage
end

#typeObject

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)