Class: Pubid::Ieee::Aiee::Identifier

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/ieee/aiee/identifier.rb

Overview

Base class for AIEE identifiers AIEE (American Institute of Electrical Engineers): 1884-1963

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Identifier

Returns a new instance of Identifier.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pubid/ieee/aiee/identifier.rb', line 21

def initialize(**args)
  super()

  # Handle number/code as string or Code object
  # Builder passes :code, but also support :number for backward compatibility
  code_value = args[:code] || args[:number]
  if code_value.is_a?(String)
    self.code = Components::Code.parse(code_value)
  elsif code_value
    self.code = code_value
  end

  # Set other attributes
  attrs = self.class.attributes
  args.each do |key, value|
    next if %i[code number].include?(key)

    setter = :"#{key}="
    public_send(setter, value) if attrs.key?(key)
  end
end

Class Method Details

.parse(input) ⇒ Object

Parse AIEE identifier string



50
51
52
53
54
# File 'lib/pubid/ieee/aiee/identifier.rb', line 50

def self.parse(input)
  parsed = Parser.new.parse(input)
  builder = Builder.new
  builder.build(parsed)
end

Instance Method Details

#numberObject

Provide number accessor for backward compatibility Returns the string representation of the code



45
46
47
# File 'lib/pubid/ieee/aiee/identifier.rb', line 45

def number
  code&.to_s
end

#to_s(date_format: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/pubid/ieee/aiee/identifier.rb', line 56

def to_s(date_format: nil)
  result = [publisher]
  result << type if type
  result << code.to_s if code

  base = result.join(" ")

  # Determine which format to use
  # Priority: explicit parameter > original_format > default (long if month/separator, short otherwise)
  format = date_format&.to_s || original_format

  if !format
    # Auto-detect from parsed attributes
    format = month || separator ? "long" : "short"
  end

  # Date formatting based on format parameter
  if year
    case format
    when "short", :short
      # Short form: dash + year
      base += "-#{year}"
    when "long", :long
      # Long form: separator + optional month + year
      sep = separator || "," # Default to comma for long form
      base += "#{sep} #{"#{month} " if month}#{year}"
    else
      # Preserve original format (backward compatibility)
      base += if separator
                "#{separator} #{"#{month} " if month}#{year}"
              elsif month
                ", #{month} #{year}"
              else
                "-#{year}"
              end
    end
  end

  # Add relationships if present
  if relationships && !relationships.empty?
    relationship_str = relationships.join(" / ")
    base += " (#{relationship_str})"
  end

  base
end