Class: TodoTxt::Todo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(todo) ⇒ Todo

Returns a new instance of Todo.



7
8
9
# File 'lib/todo_txt_rb/todo.rb', line 7

def initialize(todo)
	@todo = todo
end

Instance Attribute Details

#todoObject

Returns the value of attribute todo.



5
6
7
# File 'lib/todo_txt_rb/todo.rb', line 5

def todo
  @todo
end

Instance Method Details

#change_priority!(priority, todo = @todo) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/todo_txt_rb/todo.rb', line 36

def change_priority! priority, todo=@todo
	if todo.index(/^\([A-Z]\)/) == nil 
		@todo = "(#{priority}) " + todo
	else
		@todo = todo.sub(/^\([A-Z]\)/, "(#{priority})")
	end	
end

#contexts(todo = @todo) ⇒ Object



24
25
26
# File 'lib/todo_txt_rb/todo.rb', line 24

def contexts todo=@todo
	todo.scan(/@\w+/)
end

#creation_date(todo = @todo) ⇒ Object



28
29
30
# File 'lib/todo_txt_rb/todo.rb', line 28

def creation_date todo=@todo
	@todo = todo.scan(/\d{4}-\d{2}-\d{2}/).fetch(0)
end

#is_active?(todo = @todo) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/todo_txt_rb/todo.rb', line 52

def is_active? todo=@todo
	if todo.index(/^x/) == nil
		true
	else
		false
	end
end

#is_complete?(todo = @todo) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/todo_txt_rb/todo.rb', line 44

def is_complete? todo=@todo
	if todo.index(/^x/) == nil
		false
	else
		true
	end
end

#mark_complete!(todo = @todo) ⇒ Object



60
61
62
63
# File 'lib/todo_txt_rb/todo.rb', line 60

def mark_complete! todo=@todo
	@todo = "x #{Date.today.strftime("%F")} " + @todo 
	
end

#priority(todo = @todo) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/todo_txt_rb/todo.rb', line 11

def priority todo=@todo  
	priority = todo[/^\([a-zA-Z]\)/]
	if priority == nil
		return false 
	else
		priority.gsub(/[()]/, "").upcase
	end
end

#projects(todo = @todo) ⇒ Object



20
21
22
# File 'lib/todo_txt_rb/todo.rb', line 20

def projects todo=@todo
	todo.scan(/\+\w+/)
end

#remove_priority!(todo = @todo) ⇒ Object



32
33
34
# File 'lib/todo_txt_rb/todo.rb', line 32

def remove_priority! todo=@todo
	@todo = todo.sub(/^\([A-Z]\)/,"").strip
end