Class: Openlibrary::Covers::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/openlibrary/covers.rb

Overview

An Image from the OpenLibrary API, if one exists

Instance Method Summary collapse

Constructor Details

#initialize(identifiers, identifier_type = :isbn) ⇒ Image

Returns a new instance of Image.

Parameters:

  • identifiers (String, Array<string>)

    the actual values to look up

  • identifier_type (String, Symbol) (defaults to: :isbn)


14
15
16
17
18
19
20
21
22
# File 'lib/openlibrary/covers.rb', line 14

def initialize(identifiers, identifier_type = :isbn)
  identifiers = Array(identifiers)
  @identifier_type = identifier_type

  @found = false

  @successful_identifier = identifiers.detect { |identifier| image_exists(identifier) }
  @found = true if @successful_identifier
end

Instance Method Details

#found?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/openlibrary/covers.rb', line 24

def found?
  @found
end

#url(size = 'M') ⇒ Object

Parameters:

  • size (String, Symbol) (defaults to: 'M')

    (can be ‘S’, ‘M’, ‘L’, :S, :M, :L)



30
31
32
# File 'lib/openlibrary/covers.rb', line 30

def url(size = 'M')
  @found ? openlibrary_url(@successful_identifier, size) : nil
end