class Trackington::Task

Constants

PRIORITIES
STATUSES
TYPES

Attributes

assigned_to[R]
created_by[R]
description[R]
id[R]
priority[R]
status[R]
task_type[R]
time_actual[R]
time_planned[R]
title[R]

Public Class Methods

new(db_task) click to toggle source
# File lib/trackington/app/tasks.rb, line 66
def initialize(db_task)
  basic_properties(db_task)
  status_properties(db_task)
  person_properties(db_task)
end

Public Instance Methods

active?() click to toggle source
# File lib/trackington/app/tasks.rb, line 72
def active?
  %w(in_progress reopened open).include? @status
end
update(data) click to toggle source
# File lib/trackington/app/tasks.rb, line 76
def update(data)
  db_task = Models::Task.find(@id)

  data.each do |property, new_value|
    db_task[property] = get_value(property, new_value) if property != :id
  end

  db_task.save

  basic_properties(db_task)
  status_properties(db_task)
  person_properties(db_task)
end

Private Instance Methods

basic_properties(db_task) click to toggle source
# File lib/trackington/app/tasks.rb, line 92
def basic_properties(db_task)
  @id = db_task.id
  @title = db_task.title
  @description = db_task.description
end
get_value(property, value) click to toggle source
# File lib/trackington/app/tasks.rb, line 112
def get_value(property, value)
  case property
  when :status then STATUSES.index(value)
  when :priority then PRIORITIES.index(value)
  when :task_type then TYPES.index(value)
  else value
  end
end
person_properties(db_task) click to toggle source
# File lib/trackington/app/tasks.rb, line 107
def person_properties(db_task)
  @assigned_to = db_task.assigned_to
  @created_by = db_task.created_by
end
status_properties(db_task) click to toggle source
# File lib/trackington/app/tasks.rb, line 98
def status_properties(db_task)
  @time_planned = db_task.time_planned
  @time_actual =  db_task.time_actual

  @priority = db_task.priority
  @task_type = db_task.task_type
  @status = db_task.status
end