class Ztodo::Project
Represent Project
object.
Constants
- HIGH
- LOW
- NORMAL
Attributes
loaded[R]
Public Class Methods
new()
click to toggle source
# File lib/ztodo/project.rb, line 14 def initialize @loaded = false @data = {} end
Public Instance Methods
add(task)
click to toggle source
Add task Raise en exception if key is already used
# File lib/ztodo/project.rb, line 47 def add task raise Exception.new('Such key already exists') if @data.include?(task[:key].to_sym) @data[task[:key].to_sym] = task end
create()
click to toggle source
Create task (but not add it to data)
# File lib/ztodo/project.rb, line 68 def create new_key = 0 @data.each do |k, elem| begin curr = elem[:key].to_s.to_i new_key = curr if new_key < curr rescue end end new_key += 1 {:key=>new_key.to_s, :description=>'put description here', :done=>false, :priority=> Ztodo::Project::NORMAL} end
init!()
click to toggle source
Init project file (.ztodo) in current directory
# File lib/ztodo/project.rb, line 20 def init! @data = {} save! end
load!()
click to toggle source
load project from file in current directory
# File lib/ztodo/project.rb, line 26 def load! raise Exception.new('ztodo project file is not exists') unless File.exists?(Dir.pwd+'/.ztodo') @data = YAML::load(File.open(Dir.pwd+'/.ztodo')) @loaded = true end
modify(key, task)
click to toggle source
Modify task Raise en exception if there is no task with such key
# File lib/ztodo/project.rb, line 54 def modify key, task raise Exception.new('No task with such key') unless @data.include?(key.to_sym) @data.delete key add task end
remove(key)
click to toggle source
Remove task Raise en exception if there is no task with such key
# File lib/ztodo/project.rb, line 62 def remove key raise Exception.new('No task with such key') unless @data.include?(key.to_sym) @data.delete key end
save!()
click to toggle source
Save project to file in current directory
# File lib/ztodo/project.rb, line 34 def save! File.open(Dir.pwd + '/.ztodo', 'w+') { |f| f.write(@data.to_yaml) } @loaded = true end
tasks(show_all = FALSE)
click to toggle source
Return all tasks
# File lib/ztodo/project.rb, line 40 def tasks show_all = FALSE return @data.reject {|k,v| v[:done]} if !show_all @data.clone end