Module: Pubid::Isbn

Extended by:
PrefixesSupport
Defined in:
lib/pubid/isbn.rb,
lib/pubid/isbn/parser.rb,
lib/pubid/isbn/builder.rb,
lib/pubid/isbn/renderer.rb,
lib/pubid/isbn/identifier.rb,
lib/pubid/isbn/check_digit.rb,
lib/pubid/isbn/identifiers.rb,
lib/pubid/isbn/identifiers/book.rb

Overview

ISBN flavor — bibliographic book identifier per ISO 2108.

Parses both 10-digit (ISBN-10) and 13-digit (ISBN-13) forms with optional hyphenation. The check digit is validated; an invalid check digit raises on parse.

Defined Under Namespace

Modules: Identifiers Classes: Builder, CheckDigit, Identifier, Parser, Renderer

Constant Summary collapse

PREFIXES =
["ISBN"].freeze

Class Method Summary collapse

Methods included from PrefixesSupport

prefix_flavor_key, prefixes

Class Method Details

.all_typed_stagesObject



35
36
37
38
39
# File 'lib/pubid/isbn.rb', line 35

def self.all_typed_stages
  @all_typed_stages ||= identifier_types.flat_map do |klass|
    klass.const_defined?(:TYPED_STAGES) ? klass.const_get(:TYPED_STAGES) : []
  end
end

.identifier_typesObject



28
29
30
31
32
33
# File 'lib/pubid/isbn.rb', line 28

def self.identifier_types
  @identifier_types ||= Identifiers.constants
    .filter_map { |c| begin; Identifiers.const_get(c); rescue NameError; nil; end }
    .select { |c| c.is_a?(Class) && c.singleton_methods(false).include?(:type) }
    .select { |c| c.type.is_a?(Hash) }
end

.locate_stage(abbr) ⇒ Object



45
46
47
48
# File 'lib/pubid/isbn.rb', line 45

def self.locate_stage(abbr)
  abbr_str = abbr.to_s.upcase
  all_typed_stages.find { |s| s.abbr.any? { |a| a.to_s.upcase == abbr_str } }
end

.locate_type(code) ⇒ Object



41
42
43
# File 'lib/pubid/isbn.rb', line 41

def self.locate_type(code)
  identifier_types.find { |t| t.type[:key].to_s == code.to_s }
end

.parse(identifier) ⇒ Object



21
22
23
# File 'lib/pubid/isbn.rb', line 21

def self.parse(identifier)
  Identifier.parse(identifier)
end