Permalink
Browse files

fixed bug in isbn lookup, now distinguishes between work and book

  • Loading branch information...
1 parent 53d2566 commit d945befd7fe0573e94d67f50e57844acec3a9d6b @bensinober bensinober committed Oct 9, 2012
Showing with 37 additions and 31 deletions.
  1. +25 −23 Gemfile.lock
  2. +12 −8 app/models/book.rb
View
@@ -74,8 +74,8 @@ GEM
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.4.2)
- builder (3.0.0)
- capistrano (2.13.3)
+ builder (3.0.3)
+ capistrano (2.13.4)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
@@ -110,38 +110,39 @@ GEM
debugger-ruby_core_source (1.1.3)
diff-lcs (1.1.3)
erubis (2.7.0)
- eventmachine (0.12.10)
- excon (0.16.2)
+ eventmachine (1.0.0)
+ excon (0.16.4)
execjs (1.4.0)
multi_json (~> 1.0)
- fabrication (2.2.3)
+ fabrication (2.3.0)
fakeweb (1.3.0)
faye-websocket (0.4.6)
eventmachine (>= 0.12.0)
ffi (1.1.5)
friendly_id (4.0.8)
hashie (1.2.0)
- heroku (2.31.2)
- heroku-api (~> 0.3.4)
+ heroku (2.32.8)
+ heroku-api (~> 0.3.5)
launchy (>= 0.3.2)
netrc (~> 0.7.7)
rest-client (~> 1.6.1)
rubyzip
- heroku-api (0.3.4)
+ heroku-api (0.3.5)
excon (~> 0.16.1)
- highline (1.6.14)
+ highline (1.6.15)
hike (1.2.1)
http_parser.rb (0.5.3)
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
i18n (0.6.1)
journey (1.0.4)
- jquery-rails (2.1.1)
+ jquery-rails (2.1.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
+ jruby-pageant (1.1.1)
json (1.7.5)
- kaminari (0.14.0)
+ kaminari (0.14.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
launchy (2.1.2)
@@ -165,13 +166,14 @@ GEM
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
- net-ssh (2.5.2)
+ net-ssh (2.6.0)
+ jruby-pageant (>= 1.1.1)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
netrc (0.7.7)
nokogiri (1.5.5)
pg (0.14.1)
- poltergeist (0.7.0)
+ poltergeist (1.0.0)
capybara (~> 1.1)
childprocess (~> 0.3)
faye-websocket (~> 0.4, >= 0.4.4)
@@ -183,7 +185,7 @@ GEM
rack (>= 0.4)
rack-ssl (1.3.2)
rack
- rack-test (0.6.1)
+ rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.3)
actionmailer (= 3.2.3)
@@ -219,16 +221,16 @@ GEM
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
- rspec-expectations (2.11.2)
+ rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.11.2)
+ rspec-mocks (2.11.3)
rspec-rails (2.11.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.11.0)
rubyzip (0.9.9)
- rvm-capistrano (1.2.6)
+ rvm-capistrano (1.2.7)
capistrano (>= 2.0.0)
sass (3.2.1)
sass-rails (3.2.5)
@@ -242,15 +244,15 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
- simple_form (2.0.2)
+ simple_form (2.0.4)
actionpack (~> 3.0)
activemodel (~> 3.0)
simplecov (0.6.4)
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
- slim (1.3.0)
- temple (~> 0.4.1)
+ slim (1.3.2)
+ temple (~> 0.5.0)
tilt (~> 1.3.3)
slim-rails (1.0.3)
actionpack (~> 3.0)
@@ -263,8 +265,8 @@ GEM
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
systemu (2.5.2)
- temple (0.4.1)
- thin (1.4.1)
+ temple (0.5.4)
+ thin (1.5.0)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
@@ -280,7 +282,7 @@ GEM
multi_json (~> 1.0, >= 1.0.2)
uuid (2.3.5)
macaddr (~> 1.0)
- vcr (2.2.4)
+ vcr (2.2.5)
will_paginate (3.0.3)
xpath (0.1.4)
nokogiri (~> 1.3)
View
@@ -91,12 +91,14 @@ def find_by_isbn(isbn, conditions = {})
# retrieves :author, :cover_url, :book_id and :title
isbn = sanitize_isbn(isbn)
- query = QUERY.select(:subject, :title, :cover_url)
+ query = QUERY.select(:subject, :title, :cover_url, :work_id)
query.group_digest(:author, ', ', 1000, 1)
query.from(self.graph)
query.where(
[:subject, RDF::BIBO.isbn, "#{isbn}"],
- [:subject, RDF::DC.title, :title]
+ [:subject, RDF.type, RDF::BIBO.Document],
+ [:subject, RDF::DC.title, :title],
+ [:work_id, RDF::FABIO.hasManifestation, :subject]
)
query.optional(
[:subject, RDF::DC.creator, :creator],
@@ -112,9 +114,9 @@ def find_by_isbn(isbn, conditions = {})
return nil unless results.any?
record = results.first
-
+
# calls self.cover_url if no cover_url on book
- if record[:cover_url].blank?
+ unless record[:cover_url]
record[:cover_url] = self.cover_url(record[:subject])
end
record[:isbn] = isbn
@@ -150,10 +152,12 @@ def cover_url(subject = nil)
end
results = REPOSITORY.select(query)
- found = results.first if results.any?
-
- # return either cover_url, same_language_image, any_image or nil
- found[:cover_url] ? found[:cover_url] : found[:same_language_image] ? found[:same_language_image] : found[:any_image] ? found[:any_image] : nil
+
+ if results
+ # return either cover_url, same_language_image, any_image or nil
+ found = results.first if results.any?
+ found[:cover_url] ? found[:cover_url] : found[:same_language_image] ? found[:same_language_image] : found[:any_image] ? found[:any_image] : nil
+ end
end
end # End class methods

0 comments on commit d945bef

Please sign in to comment.