Class: Pubid::Amca::Identifiers::Base

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/amca/identifiers/base.rb

Overview

Base identifier class for ACMA identifiers Single Responsibility: Common functionality for all ACMA identifier types

Class Method Summary collapse

Instance Method Summary collapse

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, #urn_supplement_type, #urn_type_code

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.parse(string) ⇒ Object



53
54
55
# File 'lib/pubid/amca/identifiers/base.rb', line 53

def self.parse(string)
  Amca::Identifier.parse(string)
end

Instance Method Details

#base_hashObject

Override base_hash to handle AMCA-specific copublisher format (string, not array)



10
11
12
13
14
15
# File 'lib/pubid/amca/identifiers/base.rb', line 10

def base_hash
  hash = super
  # AMCA's copublisher is a string, not an array, so remove it from copublishers
  hash.delete(:copublishers) if hash[:copublishers]
  hash
end

#publisherObject

AMCA uses a fixed publisher string



24
25
26
# File 'lib/pubid/amca/identifiers/base.rb', line 24

def publisher
  "AMCA"
end

#to_sObject

Render the identifier as a string



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pubid/amca/identifiers/base.rb', line 29

def to_s
  parts = []
  parts << copublisher if copublisher
  # type is a hash, get the title
  t = self.class.attributes.key?(:type) ? type : nil
  if t.is_a?(Hash) && t[:title]
    parts << t[:title].to_s
  end
  parts << code.to_s
  parts << "-#{year}" if year

  result = parts.compact.join(" ")

  # Handle additional copublisher after year (e.g., /ASHRAE 51-16)
  if copublisher&.include?("/") && year
    type_title = t.is_a?(Hash) ? t[:title].to_s : ""
    result = "#{copublisher} #{type_title} #{code}-#{year}"
  end

  result += " (#{reaffirmed})" if reaffirmed

  result
end

#to_urnObject



57
58
59
60
# File 'lib/pubid/amca/identifiers/base.rb', line 57

def to_urn
  require_relative "../urn_generator"
  UrnGenerator.new(self).generate
end