Class: Pubid::Isbn::Identifier
Constant Summary
collapse
- ISBN_TYPE_MAP =
{
"pubid:isbn:book" => "Pubid::Isbn::Identifiers::Book",
}.freeze
- PUBLISHER =
"ISBN"
Class Method Summary
collapse
Instance Method Summary
collapse
apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Class Method Details
.parse(identifier) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/pubid/isbn/identifier.rb', line 46
def self.parse(identifier)
if identifier.length > Pubid::MAX_INPUT_LENGTH
raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
end
parsed = Parser.parse(identifier)
Builder.build(parsed)
rescue Parslet::ParseFailed => e
raise "Failed to parse ISBN '#{identifier}': #{e.message}"
rescue ArgumentError => e
raise "Failed to parse ISBN '#{identifier}': #{e.message}"
end
|
Instance Method Details
#check_digit ⇒ Object
34
35
36
|
# File 'lib/pubid/isbn/identifier.rb', line 34
def check_digit
raw.to_s[-1]
end
|
Returns :isbn10 or :isbn13.
26
27
28
29
30
31
32
|
# File 'lib/pubid/isbn/identifier.rb', line 26
def form
case raw.to_s.length
when 10 then :isbn10
when 13 then :isbn13
else raise "Invalid ISBN length: #{raw.inspect}"
end
end
|
#to_s(**opts) ⇒ Object
42
43
44
|
# File 'lib/pubid/isbn/identifier.rb', line 42
def to_s(**opts)
render(format: :human, **opts)
end
|
#valid? ⇒ Boolean
38
39
40
|
# File 'lib/pubid/isbn/identifier.rb', line 38
def valid?
CheckDigit.valid?(raw)
end
|