Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'sora/book'

* sora/book:
  Book!

Conflicts:
	db/schema.rb
  • Loading branch information...
commit f2730aa1cbc09cb497a9082d3e659b1b69397bcd 2 parents 24abb78 + a05ec21
@tenderlove authored
View
14 app/models/account.rb
@@ -47,7 +47,19 @@ def self.import io
end
(record['ruby-books'] || []).each do |key|
- account.books.create!(:key => key)
+ isbn10 = key[3..11]
+ check_digit = 0
+ isbn10.split(//).each_with_index do |c, i|
+ check_digit += c.to_i * (10 - i)
+ end
+ check_digit = 11 - (check_digit % 11)
+ check_digit = case check_digit
+ when 10; "X"
+ when 11; 0
+ else; check_digit
+ end
+ isbn10 = "#{isbn10}#{check_digit}"
+ account.books.create!(:key => key, :isbn => isbn10)
end
end
end
View
5 app/views/accounts/_account.html.erb
@@ -60,20 +60,17 @@
</tr>
<% end %>
- <!-- FIXME: unsure how to link to ISBN. :-( -->
- <!--
<% unless account.books.empty? %>
<tr>
<td>Books:</td>
<td>
<ul>
<% account.books.each do |book| %>
- <li><%= book.key %></li>
+ <li><a href="http://www.amazon.<%= book.isbn.match(/^4/) ? "co.jp":"com" %>/dp/<%= book.isbn %>"><%= book.key %></a></li>
<% end %>
</ul>
</td>
</tr>
<% end %>
- -->
</table>
</li>
View
9 db/migrate/20110112055458_add_isbn_to_books.rb
@@ -0,0 +1,9 @@
+class AddIsbnToBooks < ActiveRecord::Migration
+ def self.up
+ add_column :books, :isbn, :string
+ end
+
+ def self.down
+ remove_column :books, :isbn
+ end
+end
View
3  db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110106191812) do
+ActiveRecord::Schema.define(:version => 20110112055458) do
create_table "accounts", :force => true do |t|
t.string "username"
@@ -23,6 +23,7 @@
t.integer "account_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "isbn"
end
add_index "books", ["account_id"], :name => "index_books_on_account_id"
Please sign in to comment.
Something went wrong with that request. Please try again.