Created
December 8, 2010 00:21
-
-
Save itchy/732694 to your computer and use it in GitHub Desktop.
Worst of 2010 For Scott Johnson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Task < ActiveRecord::Base | |
| belongs_to :user | |
| belongs_to :location | |
| belongs_to :customer | |
| belongs_to :task_code | |
| validates_presence_of :location_id | |
| validates_presence_of :customer_id | |
| validates_presence_of :job_number | |
| # validates_format_of :job_number, :with => /^[5-9][0-9]{5,100}/ | |
| validates_presence_of :page, :if => (Proc.new { |task| task.group =~ /pages/ }) | |
| validates_presence_of :comments, :if => (Proc.new { |task| [51,52,53,54,100,105,110,115,120 ].include? task.task_code_id }) | |
| validates_presence_of :comments, :if => (Proc.new { |task| task.kind =~ /other/i }) # images All Other | |
| validates_presence_of :count, :unless => (Proc.new { |task| [27,28,29,30,33,34,36,37,51,52,53,54,100,105,110,115,120 ].include? task.task_code_id }) | |
| validates_presence_of :filename, :if => (Proc.new { |task| [27,28,29,30 ].include? task.task_code_id }), | |
| :message => "/ Feature Name Cannot be blank for this task" # Comics Supplied, Edits or Conversion | |
| validates_format_of :filename, :with => /^[A-z]{2,3}$/, :if => (Proc.new { |task| [27,28,29,30 ].include? task.task_code_id }), | |
| :message => "/ Feature Name must be a 2 or 3 Character Value" # Comics Supplied, Edits or Conversion | |
| validates_presence_of :page, :if => (Proc.new { |task| [27,28,29,30,31,32,35,36 ].include? task.task_code_id }), | |
| :message => "/ Week # Cannot be blank for this task" # Comics Not pagination or Other | |
| validates_inclusion_of :page, :in => (1..53).collect { |n| n.to_s }, :if => (Proc.new { |task| [27,28,29,30,31,32,35,36 ].include? task.task_code_id }), | |
| :message => "/ Week # must be between 1 and 53 " # Comics Not pagination or Other | |
| validates_numericality_of :count, :if => (Proc.new { |task| [4,5,6,7,8,18,19,1,3,10,22,23,25,35].include? task.task_code_id }) | |
| validates_length_of :comments, :maximum=> 100 | |
| # DEFAULT VALUES SET AT DATABASE | |
| # | |
| # self[:count] = 1 | |
| # self[:running] = 0 | |
| def before_save | |
| # blank out kind if | |
| # images but not silo (4) - [5,6,7,8,18,19,20] | |
| # File Distribution [21] | |
| # packaging but not Assembly (22) - [23,24,25] | |
| # Or other [100, 105, 110, 115, 120] | |
| # task is Customer Consultation [51,52,53,54] | |
| # comics task NOT supplied, edit or conversion [29,31,32,33,34,35,36,37] | |
| clear_kind_task_ids = [5,6,7,8,18,19,20,21,23,24,25,29,31,32,33,34,35,36,37,51,52,53,54,100,105,110,115,120] | |
| # blank out round if | |
| # images but not color correction (6) or artistic retouch (7) - [4,5,8,18,19,20] | |
| # File Distribution [21] | |
| # Or other [100, 105, 110, 115] | |
| # task is Customer Consultation [51,52,53,54,] | |
| # comics task NOT supplied or edit [30,31,32,33,34,35,36,37] | |
| clear_round_task_ids = [4,5,8,18,19,20,21,30,31,32,33,34,35,36,37,51,52,53,54,100,105,110,115,120] | |
| # blank out count if | |
| # task is other [100, 105, 110, 115] | |
| # task is Customer Consultation [37,51,52,53,54,] | |
| clear_count_task_ids = [37,51,52,53,54,100,105,110,115,120 ] | |
| # set count to 1 if | |
| # Comics NOT pagination, consultation QA or Other [27,28,29,30,33,34,36] | |
| clear_set_1_task_ids = [27,28,29,30,33,34,36] | |
| # blank out filename if | |
| # comics IS Supplied, Edit or Conversion, [31,32,33,34,35,36,120] | |
| clear_filename_task_ids = [31,32,33,34,35,36,120] | |
| # blank out page if | |
| # comics IS Distro, Cybrary, consultation or Other [31,32,37,120] | |
| clear_page_task_ids = [33,34,37,120] | |
| # blank out kind and round if conditions met | |
| self.kind = "" if clear_kind_task_ids.include? self.task_code_id | |
| self.round = "" if clear_round_task_ids.include? self.task_code_id | |
| self.count = "" if clear_count_task_ids.include? self.task_code_id | |
| self.filename = "" if clear_filename_task_ids.include? self.task_code_id | |
| self.page = "" if clear_page_task_ids.include? self.task_code_id | |
| self.count = "1" if clear_set_1_task_ids.include? self.task_code_id | |
| # blank out page if Packaging | |
| self.page = "" if self.group =~ /packaging/i | |
| # remove returns and ~ from comments | |
| self.comments.gsub!(/\r\n/, ' ') | |
| self.comments.gsub!(/~/, '-') # the ~ is a record seperator in the Excel Pivot Table app | |
| self.comments.squeeze!(' ') | |
| # this callback cannot return false ... | |
| return true | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment