Skip to content
This repository
Browse code

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

  • Loading branch information...
commit d945befd7fe0573e94d67f50e57844acec3a9d6b 1 parent 53d2566
Benjamin Rokseth authored October 09, 2012
48  Gemfile.lock
@@ -74,8 +74,8 @@ GEM
74 74
     arel (3.0.2)
75 75
     bcrypt-ruby (3.0.1)
76 76
     bootstrap-sass (2.0.4.2)
77  
-    builder (3.0.0)
78  
-    capistrano (2.13.3)
  77
+    builder (3.0.3)
  78
+    capistrano (2.13.4)
79 79
       highline
80 80
       net-scp (>= 1.0.0)
81 81
       net-sftp (>= 2.0.0)
@@ -110,26 +110,26 @@ GEM
110 110
     debugger-ruby_core_source (1.1.3)
111 111
     diff-lcs (1.1.3)
112 112
     erubis (2.7.0)
113  
-    eventmachine (0.12.10)
114  
-    excon (0.16.2)
  113
+    eventmachine (1.0.0)
  114
+    excon (0.16.4)
115 115
     execjs (1.4.0)
116 116
       multi_json (~> 1.0)
117  
-    fabrication (2.2.3)
  117
+    fabrication (2.3.0)
118 118
     fakeweb (1.3.0)
119 119
     faye-websocket (0.4.6)
120 120
       eventmachine (>= 0.12.0)
121 121
     ffi (1.1.5)
122 122
     friendly_id (4.0.8)
123 123
     hashie (1.2.0)
124  
-    heroku (2.31.2)
125  
-      heroku-api (~> 0.3.4)
  124
+    heroku (2.32.8)
  125
+      heroku-api (~> 0.3.5)
126 126
       launchy (>= 0.3.2)
127 127
       netrc (~> 0.7.7)
128 128
       rest-client (~> 1.6.1)
129 129
       rubyzip
130  
-    heroku-api (0.3.4)
  130
+    heroku-api (0.3.5)
131 131
       excon (~> 0.16.1)
132  
-    highline (1.6.14)
  132
+    highline (1.6.15)
133 133
     hike (1.2.1)
134 134
     http_parser.rb (0.5.3)
135 135
     httparty (0.8.3)
@@ -137,11 +137,12 @@ GEM
137 137
       multi_xml
138 138
     i18n (0.6.1)
139 139
     journey (1.0.4)
140  
-    jquery-rails (2.1.1)
  140
+    jquery-rails (2.1.3)
141 141
       railties (>= 3.1.0, < 5.0)
142 142
       thor (~> 0.14)
  143
+    jruby-pageant (1.1.1)
143 144
     json (1.7.5)
144  
-    kaminari (0.14.0)
  145
+    kaminari (0.14.1)
145 146
       actionpack (>= 3.0.0)
146 147
       activesupport (>= 3.0.0)
147 148
     launchy (2.1.2)
@@ -165,13 +166,14 @@ GEM
165 166
       net-ssh (>= 1.99.1)
166 167
     net-sftp (2.0.5)
167 168
       net-ssh (>= 2.0.9)
168  
-    net-ssh (2.5.2)
  169
+    net-ssh (2.6.0)
  170
+      jruby-pageant (>= 1.1.1)
169 171
     net-ssh-gateway (1.1.0)
170 172
       net-ssh (>= 1.99.1)
171 173
     netrc (0.7.7)
172 174
     nokogiri (1.5.5)
173 175
     pg (0.14.1)
174  
-    poltergeist (0.7.0)
  176
+    poltergeist (1.0.0)
175 177
       capybara (~> 1.1)
176 178
       childprocess (~> 0.3)
177 179
       faye-websocket (~> 0.4, >= 0.4.4)
@@ -183,7 +185,7 @@ GEM
183 185
       rack (>= 0.4)
184 186
     rack-ssl (1.3.2)
185 187
       rack
186  
-    rack-test (0.6.1)
  188
+    rack-test (0.6.2)
187 189
       rack (>= 1.0)
188 190
     rails (3.2.3)
189 191
       actionmailer (= 3.2.3)
@@ -219,16 +221,16 @@ GEM
219 221
       rspec-expectations (~> 2.11.0)
220 222
       rspec-mocks (~> 2.11.0)
221 223
     rspec-core (2.11.1)
222  
-    rspec-expectations (2.11.2)
  224
+    rspec-expectations (2.11.3)
223 225
       diff-lcs (~> 1.1.3)
224  
-    rspec-mocks (2.11.2)
  226
+    rspec-mocks (2.11.3)
225 227
     rspec-rails (2.11.0)
226 228
       actionpack (>= 3.0)
227 229
       activesupport (>= 3.0)
228 230
       railties (>= 3.0)
229 231
       rspec (~> 2.11.0)
230 232
     rubyzip (0.9.9)
231  
-    rvm-capistrano (1.2.6)
  233
+    rvm-capistrano (1.2.7)
232 234
       capistrano (>= 2.0.0)
233 235
     sass (3.2.1)
234 236
     sass-rails (3.2.5)
@@ -242,15 +244,15 @@ GEM
242 244
       libwebsocket (~> 0.1.3)
243 245
       multi_json (~> 1.0)
244 246
       rubyzip
245  
-    simple_form (2.0.2)
  247
+    simple_form (2.0.4)
246 248
       actionpack (~> 3.0)
247 249
       activemodel (~> 3.0)
248 250
     simplecov (0.6.4)
249 251
       multi_json (~> 1.0)
250 252
       simplecov-html (~> 0.5.3)
251 253
     simplecov-html (0.5.3)
252  
-    slim (1.3.0)
253  
-      temple (~> 0.4.1)
  254
+    slim (1.3.2)
  255
+      temple (~> 0.5.0)
254 256
       tilt (~> 1.3.3)
255 257
     slim-rails (1.0.3)
256 258
       actionpack (~> 3.0)
@@ -263,8 +265,8 @@ GEM
263 265
       tilt (~> 1.1, != 1.3.0)
264 266
     sqlite3 (1.3.6)
265 267
     systemu (2.5.2)
266  
-    temple (0.4.1)
267  
-    thin (1.4.1)
  268
+    temple (0.5.4)
  269
+    thin (1.5.0)
268 270
       daemons (>= 1.0.9)
269 271
       eventmachine (>= 0.12.6)
270 272
       rack (>= 1.0.0)
@@ -280,7 +282,7 @@ GEM
280 282
       multi_json (~> 1.0, >= 1.0.2)
281 283
     uuid (2.3.5)
282 284
       macaddr (~> 1.0)
283  
-    vcr (2.2.4)
  285
+    vcr (2.2.5)
284 286
     will_paginate (3.0.3)
285 287
     xpath (0.1.4)
286 288
       nokogiri (~> 1.3)
20  app/models/book.rb
@@ -91,12 +91,14 @@ def find_by_isbn(isbn, conditions = {})
91 91
       # retrieves :author, :cover_url, :book_id and :title
92 92
       isbn = sanitize_isbn(isbn)
93 93
 
94  
-      query = QUERY.select(:subject, :title, :cover_url)
  94
+      query = QUERY.select(:subject, :title, :cover_url, :work_id)
95 95
       query.group_digest(:author, ', ', 1000, 1)
96 96
       query.from(self.graph)
97 97
       query.where(
98 98
         [:subject, RDF::BIBO.isbn, "#{isbn}"],
99  
-        [:subject, RDF::DC.title, :title]
  99
+        [:subject, RDF.type, RDF::BIBO.Document],
  100
+        [:subject, RDF::DC.title, :title],
  101
+        [:work_id, RDF::FABIO.hasManifestation, :subject]
100 102
         )
101 103
       query.optional(
102 104
         [:subject, RDF::DC.creator, :creator],
@@ -112,9 +114,9 @@ def find_by_isbn(isbn, conditions = {})
112 114
       return nil unless results.any?
113 115
 
114 116
       record = results.first
115  
-      
  117
+
116 118
       # calls self.cover_url if no cover_url on book
117  
-      if record[:cover_url].blank? 
  119
+      unless record[:cover_url] 
118 120
         record[:cover_url] = self.cover_url(record[:subject])
119 121
       end
120 122
       record[:isbn] = isbn
@@ -150,10 +152,12 @@ def cover_url(subject = nil)
150 152
       end
151 153
             
152 154
       results = REPOSITORY.select(query)
153  
-      found = results.first if results.any?
154  
-
155  
-      # return either cover_url, same_language_image, any_image or nil
156  
-      found[:cover_url] ? found[:cover_url] : found[:same_language_image] ? found[:same_language_image] : found[:any_image] ? found[:any_image] : nil
  155
+      
  156
+      if results
  157
+        # return either cover_url, same_language_image, any_image or nil
  158
+        found = results.first if results.any?
  159
+        found[:cover_url] ? found[:cover_url] : found[:same_language_image] ? found[:same_language_image] : found[:any_image] ? found[:any_image] : nil
  160
+      end
157 161
     end
158 162
 
159 163
   end  # End class methods

0 notes on commit d945bef

Please sign in to comment.
Something went wrong with that request. Please try again.