Module: Todo::Helpers::Tasks

Extended by:
Tasks
Included in:
Tasks
Defined in:
lib/to-do/helpers/helpers_tasks.rb

Overview

Helper methods used in the Todo::Tasks module

Instance Method Summary collapse

Instance Method Details

#update_task(is_num, names, task, key, value) ⇒ Object

Update a task

Parameters:

  • is_num (Bool)

    is the task a number

  • names (Dataset)

    a dataset of all the tasks in the working list

  • task

    the task name or number that we are updating

  • key (Symbol)

    the key we are updating

  • value (Integer)

    the value that we are changing it too.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/to-do/helpers/helpers_tasks.rb', line 15

def update_task is_num, names, task, key, value
	if is_num
		found_task = names[:Task_number => task]
		if found_task
			Helpers::DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(key => value)
		else
			puts "Task ##{task} is not in the list."
		end
	else
		found_task = names.with_sql("SELECT * FROM :table WHERE Name = :task COLLATE NOCASE",:table=>names, :task=>task).first
		if found_task
			Helpers::DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(key => value)
		else
			puts "Task '#{task}' is not in the list."
		end
	end
end