Class: Google::Book::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/google/book/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Entry

Returns a new instance of Entry.



9
10
11
# File 'lib/google/book/entry.rb', line 9

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/google/book/entry.rb', line 7

def hash
  @hash
end

Instance Method Details

#coverObject



13
14
15
# File 'lib/google/book/entry.rb', line 13

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

#creatorsObject



17
18
19
# File 'lib/google/book/entry.rb', line 17

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

#dateObject



21
22
23
# File 'lib/google/book/entry.rb', line 21

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

#descriptionObject



25
26
27
# File 'lib/google/book/entry.rb', line 25

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

#formatObject



29
30
31
32
33
# File 'lib/google/book/entry.rb', line 29

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

#infoObject



35
36
37
# File 'lib/google/book/entry.rb', line 35

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

#isbnObject



72
73
74
75
76
77
78
# File 'lib/google/book/entry.rb', line 72

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

  ISBN.to_13($1) rescue nil
end

#previewObject



39
40
41
# File 'lib/google/book/entry.rb', line 39

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

#publisherObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/google/book/entry.rb', line 43

def publisher
  publisher = @hash['dc:publisher']

  if publisher
    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
end

#ratingObject



60
61
62
# File 'lib/google/book/entry.rb', line 60

def rating
  @hash['gd:rating']['average'].to_f rescue nil
end

#subjectsObject



64
65
66
# File 'lib/google/book/entry.rb', line 64

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

#titleObject



68
69
70
# File 'lib/google/book/entry.rb', line 68

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