Permalink
Browse files

due_date logic and adding to shelf by month

  • Loading branch information...
1 parent 212784c commit 3463978369c167e4facd19641530c2106ac80cea @ChrisNolan committed Aug 26, 2012
Showing with 25 additions and 6 deletions.
  1. +2 −2 bin/tpl-checked-out.rb
  2. +14 −2 lib/checkout.rb
  3. +9 −2 spec/checkout_spec.rb
@@ -22,8 +22,8 @@
shelf_names_by_book = goodreads.shelf_names_by_book(goodreads_book_id)
shelves << 'to-read' if shelf_names_by_book.empty? # in theory if it's just checked out I haven't read it yet, and the default goodreads action when I add a never seen book before to another shelf is to also add it to the 'read' shelf.
shelves << 'checked-out'
- shelves << "checked-out-#{Time.now.year}"
- #goodreads.add_to_shelf "checked-out-#{Time.now.year}-#{Time.now.month}", goodreads_book_id # track what was checked out each month... but first add check to walk back 3 weeks from the renew date so it doesn't fill multiple months un-necessarily
+ shelves << "checked-out-#{checkout.checked_out_date.year}"
+ shelves << "checked-out-#{checkout.checked_out_date.year}-#{checkout.checked_out_date.month}", goodreads_book_id # track what was checked out each month...
shelves << 'currently-checked-out'
goodreads.add_to_shelf shelves, goodreads_book_id
else
View
@@ -4,7 +4,7 @@
class Checkout
attr_accessor :title, :library_id, :local_format, :renew_count, :due_date, :unparsed_extra_detail
- def initialize(title, library_id="", local_format="", renew_count="", due_date="")
+ def initialize(title, library_id="", local_format="", renew_count=0, due_date=nil)
@title = title
@library_id = library_id
@local_format = local_format
@@ -22,6 +22,11 @@ def href=(x)
@library_id = right if right
end
+ def checked_out_date
+ # lots of assumptions -- 21 days per check out, and renewed on the date it was due
+ due_date - ((renew_count+1)*21)
+ end
+
def self.parse_from_html(row)
columns = row.css "td"
input_field = columns[0] % "input"
@@ -36,9 +41,16 @@ def self.parse_from_html(row)
title = "Uncatalogued"
end
local_format = (columns[1] % "em").children.first.to_s
- c = Checkout.new(title,"",local_format)
+ due_date = parse_due_date_field(columns[3].inner_text.strip)
+ c = Checkout.new(title,"",local_format,columns[2].inner_text.to_i,due_date)
c.href=href if href
c.unparsed_extra_detail = unparsed_extra_detail
c
end
+
+ def self.parse_due_date_field(due_date_field)
+ raw_due_date,raw_time = due_date_field.split ','
+ day, month, year = raw_due_date.split '/'
+ due_date = Date.new(year.to_i, month.to_i, day.to_i)
+ end
end
View
@@ -48,8 +48,15 @@
it "has a local format" do
@checkout.local_format.must_equal "Book"
end
- it "has the renew count"
- it "has the renew date"
+ it "has the renew count" do
+ @checkout.renew_count.must_equal 2
+ end
+ it "has the due date" do
+ @checkout.due_date.to_s.must_equal Date.new(2012,8,15).to_s
+ end
+ it 'estimates when the item was checked out' do
+ @checkout.checked_out_date.to_s.must_equal Date.new(2012,6,13).to_s
+ end
it "has unparsed extra detail" do
@checkout.unparsed_extra_detail.must_equal "RENEW^37131121201545^621.8 ROB^1^Roberts, Dustyn.^Making things move : DIY mechanisms for inventors, hobbyists, and artists^"
end

0 comments on commit 3463978

Please sign in to comment.