Class: OpenLibraryBook

Inherits:
OpenLibraryEntry show all
Defined in:
lib/fetchworks.rb

Overview

A class that represents books in the OpenLibrary database It exposes the JSON representation that OL provides through their API as a hash through @data, and as methods with method_missing, and handles some comple

Instance Attribute Summary

Attributes inherited from OpenLibraryEntry

#data

Instance Method Summary collapse

Methods included from HashMethodable

#method_missing, #respond_to_missing?

Constructor Details

#initialize(ident) ⇒ OpenLibraryBook

Identifier is assumed to be ISBN10/ISBN13 TODO: Add a check or identification type



180
181
182
# File 'lib/fetchworks.rb', line 180

def initialize(ident)
  super OpenLibrary.get_book(ident)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HashMethodable

Instance Method Details

#fetch_authorsObject



189
190
191
192
193
# File 'lib/fetchworks.rb', line 189

def fetch_authors
  authors.collect do |author|
    OpenLibraryAuthor.new author["url"]
  end
end

#publish_dateObject



184
185
186
187
# File 'lib/fetchworks.rb', line 184

def publish_date
  str = @data["publish_date"]
  OpenLibrary.partial_date_from_str(str)
end