class Object
Public Instance Methods
add_task(hash, task)
click to toggle source
# File lib/task.rb, line 33 def add_task(hash, task) hash ||= {} task_hash = {} for x in hash.keys task_hash[x] = hash[x] end if task[:link].nil? return puts 'task is missing link' end if task[:name].nil? return puts 'task is missing name' end if task[:time_added].nil? return puts 'missing time added' end if task[:complete].nil? return puts 'missing completed field' end link_str = task[:link] task_hash[link_str] = task return task_hash end
add_to_settings(question_input, condition)
click to toggle source
# File lib/setup.rb, line 12 def add_to_settings(question_input, condition) raise "The question is not a string" unless question_input.class == String Taskington::ask_question(question_input) response = $stdin.gets.chomp.capitalize if condition.(response) == false add_to_settings(question_input, condition) end return response end
create_daily_tasks()
click to toggle source
# File lib/task.rb, line 3 def create_daily_tasks tasks = {'date' => Time.new, 'tasks' => {}} tasks_json = JSON.generate(tasks) return tasks_json end
create_task(name, complete = 0, link = nil)
click to toggle source
# File lib/task.rb, line 9 def create_task(name, complete = 0, link = nil) task_hash = {} if name == '' return 'your task must have a name' else task_hash[:name] = name end if complete == 0 task_hash[:complete] = 'false' elsif complete == 1 task_hash[:complete] == 'true' end task_hash[:time_added] = Time.new link_string = task_hash[:name][0..2] + String(SecureRandom.hex(2)) task_hash[:link] = link_string task_hash[:time_spent] = 0 return task_hash end
set_up_task_dir()
click to toggle source
# File lib/setup.rb, line 1 def set_up_task_dir if Dir.exist?(File.join(Dir.home, '.taskington')) return puts 'the taskington directory already exists on your system' end knight = File.read('./lib/knight.data') puts knight Dir.mkdir(File.join(Dir.home, '.taskington'), 0700) end
set_up_user()
click to toggle source
# File lib/setup.rb, line 25 def set_up_user settings = {} settings["username"] = add_to_settings('What be thine name?', lambda { |str| str.class == String }) settings["weekly_task_num"] = add_to_settings('How many tasks per week must thou slay? (max: 15)', lambda { |num| num.to_i != 0 && num.length < 3 && num.to_i < 16}) settings["daily_task_num"] = add_to_settings('How many tasks per day? (max: 3)', lambda { |num| num.to_i != 0 && num.length < 2 && num.to_i < 4}) settings["work_week_start"] = add_to_settings('When dost thou work week start? (Mon, Tues, Wed, Thur, Fri, Sat, Sun)', lambda { |str| ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'].include? str }) settings["work_week_end"] = add_to_settings('When dost thou work week end? (Mon, Tues, Wed, Thur, Fri, Sat, Sun)', lambda { |str| ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'].include? str }) puts "username #{settings["username"]}" puts "weekly_task_num #{settings["weekly_task_num"]}" puts "daily_task_num #{settings["daily_task_num"]}" puts "work_week_start #{settings["work_week_start"]}" puts "work_week_end #{settings["work_week_start"]}" Taskington::ask_question('Dost this look correct?[y, yes]') choice = $stdin.gets.chomp if choice == 'yes' || choice == 'y' return File.open(File.join(Dir.home, '.taskington/settings.json'), 'w') do |f| f.write(JSON.pretty_generate(settings)) end end Taskington::ask_question('Are you sure? If thou art sure I will implore you for your credentials once more [yes to be sure]') choice = $stdin.gets.chomp if choice == 'yes' || choice == 'y' return File.open(File.join(Dir.home, '.taskington/user.json'), 'w') do |f| f.write(JSON.pretty_generate(settings)) end end # the user chooses no and wants to reset some settings set_up_user end