Class: Google::Book::Entry
- Inherits:
-
Object
- Object
- Google::Book::Entry
- Defined in:
- lib/google/book/entry.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #cover ⇒ Object
- #creators ⇒ Object
- #date ⇒ Object
- #description ⇒ Object
- #format ⇒ Object
- #info ⇒ Object
-
#initialize(hash) ⇒ Entry
constructor
A new instance of Entry.
- #isbn ⇒ Object
- #preview ⇒ Object
- #publisher ⇒ Object
- #rating ⇒ Object
- #subjects ⇒ Object
- #title ⇒ Object
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
#hash ⇒ Object (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
#cover ⇒ Object
13 14 15 |
# File 'lib/google/book/entry.rb', line 13 def cover Cover.new(@hash['link'][0]['href']) end |
#creators ⇒ Object
17 18 19 |
# File 'lib/google/book/entry.rb', line 17 def creators [@hash['dc:creator']].flatten.join(', ') end |
#date ⇒ Object
21 22 23 |
# File 'lib/google/book/entry.rb', line 21 def date @hash['dc:date'] end |
#description ⇒ Object
25 26 27 |
# File 'lib/google/book/entry.rb', line 25 def description @hash['dc:description'] end |
#format ⇒ Object
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 |
#info ⇒ Object
35 36 37 |
# File 'lib/google/book/entry.rb', line 35 def info @hash['link'][1]['href'] end |
#isbn ⇒ Object
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 |
#preview ⇒ Object
39 40 41 |
# File 'lib/google/book/entry.rb', line 39 def preview @hash['link'][2]['href'] end |
#publisher ⇒ Object
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 |
#rating ⇒ Object
60 61 62 |
# File 'lib/google/book/entry.rb', line 60 def @hash['gd:rating']['average'].to_f rescue nil end |
#subjects ⇒ Object
64 65 66 |
# File 'lib/google/book/entry.rb', line 64 def subjects @hash['dc:subject'] end |
#title ⇒ Object
68 69 70 |
# File 'lib/google/book/entry.rb', line 68 def title [@hash['dc:title']].flatten.join(': ') end |