Class: J

Inherits:
Object
  • Object
show all
Defined in:
lib/j.rb

Instance Method Summary collapse

Constructor Details

#initializeJ

Returns a new instance of J.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/j.rb', line 4

def initialize
  userHome = Etc.getpwuid.dir
  if File.exists?(Dir.pwd << "/.todo")
    @tFilePath = Dir.pwd << "/.todo"
    if (Dir.pwd == userHome)
      @globalTodo = true
    else
      @globalTodo = false
    end
  else
    @globalTodo = true
    @tFilePath = userHome << '/' << ".todo"
  end
end

Instance Method Details

#addTask(task) ⇒ Object



19
20
21
22
23
# File 'lib/j.rb', line 19

def addTask(task)
  taskRecord = createTask task
  puts "*NEW* " << "TODO".foreground(:red).bright << " " << task
  writeTaskToFile taskRecord
end

#clearListObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/j.rb', line 71

def clearList
  if File.exists?(@tFilePath)
    File.delete(@tFilePath)
  end
  if @globalTodo
    puts "Cleared todo list"
  else
    puts "Cleared project todo list"
  end
end

#deleteTask(key) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/j.rb', line 54

def deleteTask(key)
  readTasks
  key = key.to_i
  if key <= @tasks.count
    task = @tasks[key]
    @tasks.delete_at(key)
    if task[:status] == "TODO"
      puts "Deleted " << task[:status].color(:red).bright << " " << task[:title]
    else
      puts "Deleted " << task[:status].color(:green).bright << " " << task[:title]
    end
    dumpTasksToFile
  else
    puts "No such task found!"
  end
end

#listTasks(listType = :todo) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/j.rb', line 25

def listTasks(listType=:todo)
  readTasks
  if @tasks.count > 0
    @tasks.each_with_index do |task, i|
      if ((task[:status] == "DONE" and (listType == :done or listType==:all)) or (task[:status] == "TODO" and (listType == :todo or listType==:all)))
        puts formatTask(task, i)
      end
    end
  else
    if @globalTodo
      puts "No tasks!"
    else
      puts "No tasks in project todo list. To delete project todo list use option -c"
    end
  end
end

#markTask(key) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/j.rb', line 42

def markTask(key)
  readTasks
  key = key.to_i
  if (key <= @tasks.length)
    @tasks[key].store(:status, "DONE")
    puts "DONE".color(:green).bright << " " << @tasks[key][:title]
    dumpTasksToFile
  else
    puts "No such task found!"
  end
end

#validKey(key) ⇒ Object



82
83
84
# File 'lib/j.rb', line 82

def validKey(key)
  return true unless key.match(/\A[0-9]+\Z/).nil?
end