Sha256: 84d3d9d20fbd948ef9f2abdca4c875ebc3eccd354abcfbc2d5c94f5c2e191954

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'bookland'
require 'google/book/cover'

module Google
  module Book
    class Entry
      def initialize(hash)
        @hash = hash
      end

      def cover
        Cover.new(@hash['link'][0]['href'])
      end

      def creators
        [@hash['dc:creator']].flatten.join(', ')
      end

      def date
        @hash['dc:date']
      end

      def description
        @hash['dc:description']
      end

      def format
        [@hash['dc:format']].flatten.reject do |format|
          format == 'book'
        end.join(', ')
      end

      def info
        @hash['link'][1]['href']
      end

      def preview
        @hash['link'][2]['href']
      end

      def publisher
        @hash['dc:publisher'].
          gsub(/[ ,]+Inc.?$/, '').
          gsub(/[ ,]+Llc.?$/i, '').
          gsub(/[ ,]+Ltd.?$/, '').
          gsub(/Intl( |$)/) { "International#{$1}" }.
          gsub(/Pr( |$)/) { "Press#{$1}" }.
          gsub(/ Pub$/, ' Publishers').
          gsub(/ Pubns$/, ' Publications').
          gsub('Pub Group', 'Publishing Group').
          gsub(/Univ( |$)/) { "University#{$1}" }
      end

      def subjects
        @hash['dc:subject']
      end

      def title
        [@hash['dc:title']].flatten.join(': ')
      end

      def isbn
        @hash['dc:identifier'].detect do |identifier|
          identifier.match(/ISBN:([0-9X]{10,13})/)
        end

        ISBN.to_13($1) rescue nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
google-book-0.3.2 lib/google/book/entry.rb
google-book-0.3.1 lib/google/book/entry.rb