Class: Pubid::Ansi::SingleIdentifier

Inherits:
Identifier show all
Defined in:
lib/pubid/ansi/single_identifier.rb

Overview

Single ANSI identifier (non-bundled)

Instance Method Summary collapse

Methods inherited from Identifier

parse

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

#language_portionObject



38
39
40
41
42
# File 'lib/pubid/ansi/single_identifier.rb', line 38

def language_portion
  return "" unless languages&.any?

  "(#{languages.map(&:code).join(',')})"
end

#number_portionObject



30
31
32
33
34
35
36
# File 'lib/pubid/ansi/single_identifier.rb', line 30

def number_portion
  [
    number.value,
    (part ? "-#{part.value}" : ""),
    (date ? ":#{date.year}" : ""),
  ].join
end

#publisher_portionObject



20
21
22
23
24
25
26
27
28
# File 'lib/pubid/ansi/single_identifier.rb', line 20

def publisher_portion
  if copublishers&.any?
    # ANSI/ISO 9899
    ([publisher] + copublishers).map(&:body).join("/")
  else
    # ANSI X3.4
    publisher.body
  end
end

#to_s(lang: :en) ⇒ String

Generate URN for this identifier

Returns:

  • (String)

    URN representation



11
12
13
14
15
16
17
18
# File 'lib/pubid/ansi/single_identifier.rb', line 11

def to_s(lang: :en)
  [].tap do |parts|
    parts << publisher_portion
    parts << number_portion
  end.compact.join(" ").tap do |s|
    s << language_portion if languages&.any?
  end
end