Permalink
Browse files

Transition detection in the account updater for first three cases

  • Loading branch information...
1 parent 0afbeb9 commit ef1d737a03709ca26960bb7fbffd1bed0279d3b8 @MissingHandle MissingHandle committed Nov 21, 2009
View
@@ -5,6 +5,8 @@ class User < ActiveRecord::Base
include Authentication::ByPassword
include Authentication::ByCookieToken
include Authorization::AasmRoles
+
+ has_many :items
validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true
validates_length_of :name, :maximum => 100
View
@@ -9,10 +9,36 @@ def initialize(user, crawler)
def run
parser = CplParser.new(:all => @crawler.checked_out_page)
- parser.items.each do |item|
- item.user = @user
- item.save!
- end
+ items = parser.items.map{|item| item.user = @user; item}
+ items -= handle_transition('Held','Checked out', items)
+ items -= handle_transition('Checked out', 'Overdue', items)
+ items -= handle_brand_new(items)
end
+
+ private
+ def handle_transition(old_status, new_status, items)
+ handled_items = []
+ # I want to see if the items from checked out were in the past held
+ items.find_all{|item| item.status == new_status}.each do | item|
+ if real_item = @user.items.find(:first, :conditions => {:title => item.title, :status => old_status})
+ real_item.status = new_status
+ real_item.save
+ handled_items << item
+ end
+ end
+ handled_items
+ end
+
+
+ def handle_brand_new(items)
+ handled_items = []
+ items.each do |item|
+ unless @user.items.find(:first, :conditions => {:title => item.title})
+ item.save!
+ handled_items << item
+ end
+ end
+ handled_items
+ end
end
View
@@ -42,7 +42,7 @@ def overdue_items
items = []
rows.each do |row|
row = row.css('td')
- items << Item.new(:title => row[1].content, :status => 'Checked out', :due_date => row[3].content)
+ items << Item.new(:title => row[1].content, :status => 'Overdue', :due_date => row[3].content)
end
items
@@ -1,54 +0,0 @@
-body { background-color: #fff; color: #333; }
-
-body, p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px;
-}
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px;
-}
-
-a { color: #000; }
-a:visited { color: #666; }
-a:hover { color: #fff; background-color:#000; }
-
-.fieldWithErrors {
- padding: 2px;
- background-color: red;
- display: table;
-}
-
-#errorExplanation {
- width: 400px;
- border: 2px solid red;
- padding: 7px;
- padding-bottom: 12px;
- margin-bottom: 20px;
- background-color: #f0f0f0;
-}
-
-#errorExplanation h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- background-color: #c00;
- color: #fff;
-}
-
-#errorExplanation p {
- color: #333;
- margin-bottom: 0;
- padding: 5px;
-}
-
-#errorExplanation ul li {
- font-size: 12px;
- list-style: square;
-}
-
Oops, something went wrong.

0 comments on commit ef1d737

Please sign in to comment.