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_identifier.
-
#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.
- #to_s ⇒ Object
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code
Constructor Details
This class inherits a constructor from Pubid::Identifier
Instance Method Details
#==(other) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 64 def ==(other) return false unless other.class == self.class base_identifier == other.base_identifier && letter == other.letter end |
#base_hash ⇒ Object
Override base_hash to extract edition, type, and annex from base_identifier
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 27 def base_hash hash = super # For Plateau supplements, edition comes from the base identifier if base_identifier.class.attributes.key?(:edition) && base_identifier.edition hash[:edition] = base_identifier.edition end # Include type from base_identifier if base_identifier.class.attributes.key?(:type_string) && base_identifier.type_string hash[:type] = base_identifier.type_string end # Include annex from base_identifier if base_identifier.class.attributes.key?(:annex) && base_identifier.annex hash[:annex] = base_identifier.annex end hash end |
#extract_supplement_type(supplement) ⇒ Object
Extract supplement type from class name
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 53 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
45 46 47 48 49 50 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 45 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 |
#to_s ⇒ Object
22 23 24 |
# File 'lib/pubid/plateau/supplement_identifier.rb', line 22 def to_s "#{base_identifier} #{supplement_string}" end |