Class: Pubid::Plateau::SupplementIdentifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Plateau::SupplementIdentifier
- Defined in:
- lib/pubid/plateau/supplement_identifier.rb
Overview
Base class for PLATEAU supplements (Annex) Supplements reference a base identifier
Direct Known Subclasses
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#base_hash ⇒ Object
Override base_hash to extract edition, type, and annex from base.
-
#extract_supplement_type(supplement) ⇒ Object
Extract supplement type from class name.
- #publisher ⇒ Object
-
#supplement_hash(supplement) ⇒ Object
Override supplement_hash to include letter instead of number.
-
#supplement_string ⇒ Object
Subclasses must implement supplement_string.
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
60 61 62 63 64 65 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 60 def ==(other) return false unless other.class == self.class base == other.base && letter == other.letter end |
#base_hash ⇒ Object
Override base_hash to extract edition, type, and annex from base
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 23 def base_hash hash = super # For Plateau supplements, edition comes from the base identifier if base.class.attributes.key?(:edition) && base.edition hash[:edition] = base.edition end # Include type from base if base.class.attributes.key?(:type_string) && base.type_string hash[:type] = base.type_string end # Include annex from base if base.class.attributes.key?(:annex) && base.annex hash[:annex] = base.annex end hash end |
#extract_supplement_type(supplement) ⇒ Object
Extract supplement type from class name
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 49 def extract_supplement_type(supplement) return nil unless supplement.class # Get class name without namespace class_name = supplement.class.name.to_s parts = class_name.split("::") simple_name = parts.last # Convert camel case to snake case (Annex -> annex) simple_name&.gsub(/([a-z])([A-Z])/, '\1_\2')&.downcase end |
#publisher ⇒ Object
13 14 15 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 13 def publisher "PLATEAU" end |
#supplement_hash(supplement) ⇒ Object
Override supplement_hash to include letter instead of number
41 42 43 44 45 46 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 41 def supplement_hash(supplement) { type: extract_supplement_type(supplement), letter: supplement.letter, }.compact end |
#supplement_string ⇒ Object
Subclasses must implement supplement_string
18 19 20 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 18 def supplement_string raise NotImplementedError, "Subclasses must implement supplement_string" end |