Class: Pubid::Etsi::Identifiers::SupplementIdentifier

Inherits:
Pubid::Etsi::Identifier show all
Defined in:
lib/pubid/etsi/identifiers/supplement_identifier.rb

Overview

Identifier class for ETSI supplements (Amendment, Corrigendum)

Direct Known Subclasses

Amendment, Corrigendum

Instance Method Summary collapse

Methods inherited from Pubid::Etsi::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

Instance Method Details

#==(other) ⇒ Object



91
92
93
94
95
96
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 91

def ==(other)
  return false unless other.is_a?(SupplementIdentifier)
  return false unless other.class == self.class

  base == other.base && number == other.number
end

#base_from_kv(model, value) ⇒ Object

Re-dispatch through the flavor base so _type resolves to the concrete EtsiStandard; a bare polymorphic cast would rebuild a plain Identifier and lose the subclass (and its custom mappings). Mirrors JCGM.



37
38
39
40
41
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 37

def base_from_kv(model, value)
  return unless value

  model.base = Pubid::Etsi::Identifier.from_hash(value)
end

#base_hashObject

Include supplement notation in serialization



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 99

def base_hash
  hash = super
  # ETSI supplements need the type (e.g., "ETS", "TR") from the base document
  if base.class.attributes.key?(:type) && base.type
    hash[:type] =
      base.type
  end
  hash[:supplement_notation] = supplement_notation
  hash[:supplement_type] = self.class.name.split("::").last.downcase
  hash
end

#base_to_kv(model, doc) ⇒ Object

Serialize the base via its own to_hash so it collapses to the compact EtsiStandard shape.



24
25
26
27
28
29
30
31
32
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 24

def base_to_kv(model, doc)
  return unless model.base

  doc.add_child(
    Lutaml::KeyValue::DataModel::Element.new(
      "base", model.base.to_hash
    ),
  )
end

#codeObject



48
49
50
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 48

def code
  base.code
end

#collect_supplement_notations(current_supplement, notations) ⇒ Object

Recursively collect supplement notations from the supplement chain



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 63

def collect_supplement_notations(current_supplement, notations)
  if current_supplement.is_a?(SupplementIdentifier)
    # Add this supplement's notation at the beginning (because supplements wrap from outside in)
    notations.unshift("/#{current_supplement.supplement_notation}")
    # Continue collecting from the base if it's also a supplement
    if current_supplement.base.is_a?(SupplementIdentifier)
      collect_supplement_notations(current_supplement.base, notations)
    else
      notations
    end
  else
    notations
  end
end

#dateObject



56
57
58
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 56

def date
  base.date
end

#find_actual_base(current_base) ⇒ Object

Find the actual base ETSI standard (not supplements)



79
80
81
82
83
84
85
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 79

def find_actual_base(current_base)
  if current_base.is_a?(SupplementIdentifier)
    find_actual_base(current_base.base)
  else
    current_base
  end
end

#supplement_notationObject

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 87

def supplement_notation
  raise NotImplementedError
end

#typeObject

Inherit attributes from base



44
45
46
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 44

def type
  base.type
end

#versionObject



52
53
54
# File 'lib/pubid/etsi/identifiers/supplement_identifier.rb', line 52

def version
  base.version
end