Class: Pubid::Iso::Identifiers::Base

Inherits:
Pubid::Identifier show all
Defined in:
lib/pubid/iso/identifiers/base.rb

Overview

Base class for ISO identifiers

Direct Known Subclasses

TcDocument

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pubid::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

Class Method Details

.rendering_contextObject

ISO rendering context singleton



15
16
17
# File 'lib/pubid/iso/identifiers/base.rb', line 15

def self.rendering_context
  @rendering_context ||= Pubid::Rendering::RenderingContext.iso
end

Instance Method Details

#==(other) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/pubid/iso/identifiers/base.rb', line 102

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

  publisher == other.publisher &&
    type == other.type &&
    number == other.number &&
    part == other.part &&
    date == other.date &&
    stage == other.stage
end

#copublishersObject

V1 API compatibility - tests expect .copublishers returning array of Publisher objects



94
95
96
97
98
99
100
# File 'lib/pubid/iso/identifiers/base.rb', line 94

def copublishers
  return [] unless publisher.copublisher&.any?

  publisher.copublisher.map do |cp|
    ::Pubid::Components::Publisher.new(body: cp)
  end
end

#to_s(lang: :en, lang_single: false, with_edition: false) ⇒ String

Render identifier using OOP approach - each component renders itself

Parameters:

  • lang (Symbol) (defaults to: :en)

    language for rendering (:en or :fr)

  • lang_single (Boolean) (defaults to: false)

    use single char language format

  • with_edition (Boolean) (defaults to: false)

    include edition in output

Returns:

  • (String)

    formatted identifier string



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pubid/iso/identifiers/base.rb', line 25

def to_s(lang: :en, lang_single: false, with_edition: false)
  # Create rendering context with language settings
  context = Pubid::Rendering::RenderingContext.new(
    stage_separator: "/",
    stage_separator_with_copublisher: " ",
    type_separator: "/",
    type_separator_with_prefix: " ",
    default_type_abbr: "IS",
    lang: lang,
    lang_single: lang_single,
  )

  # Compose the identifier from component renderings
  render_from_components(context: context, with_edition: with_edition)
end