Class: Pubid::CenCenelec::Identifiers::Base

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

Overview

Base CEN identifier Format: PUBLISHER NUMBER:YEAR

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

Constructor Details

This class inherits a constructor from Pubid::Identifier

Instance Method Details

#==(other) ⇒ Object



66
67
68
69
70
71
# File 'lib/pubid/cen_cenelec/identifiers/base.rb', line 66

def ==(other)
  return false unless other.is_a?(Base)

  publisher == other.publisher && number == other.number &&
    parts == other.parts && year == other.year
end

#publisherString

Generate URN for this identifier

Returns:

  • (String)

    URN representation



13
# File 'lib/pubid/cen_cenelec/identifiers/base.rb', line 13

attribute :publisher, :string, collection: true

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pubid/cen_cenelec/identifiers/base.rb', line 23

def to_s
  result = ""

  # Stage or Publisher
  if stage
    result += stage
  elsif publisher&.any?
    result += publisher.join("/")
  end

  # If we have adopted_identifier, render it (contains all info)
  if adopted_identifier
    result += " #{adopted_identifier}"
    # Don't add our own number/parts/year - they're in adopted_identifier
  else
    # Only render our own fields if no adoption
    # Type - use space for Guide, slash for TR/TS
    if type
      sep = type == "Guide" ? " " : "/"
      result += "#{sep}#{type}"
    end

    result += " #{number}"
    result += parts.map { |p| "-#{p}" }.join if parts&.any?
    result += ":#{year}" if year

    # Supplements
    if supplements&.any?
      supplements.each do |supp|
        sep = supp[:type] == :amendment ? "/" : "+"
        result += "#{sep}#{supp[:type] == :amendment ? 'A' : 'AC'}"
        result += supp[:number] if supp[:number] && !supp[:number].empty?
        result += ":#{supp[:year]}" if supp[:year]
      end
    end

    # Edition
    result += " ED#{edition}" if edition
  end

  result
end