class TasksCollection
Public Class Methods
display_header()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 47 def self.display_header "#{'-'*132}\n| #{'id:'.ljust(8)}#{'title:'.ljust(80)}#{'created:'.ljust(30)}#{'priority:'.ljust(10)} |\n#{'-'*132}" end
new()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 7 def initialize create unless File.exists? @@location @yaml = YAML.load_file(@@location) @tasks = @yaml ? @yaml['tasks'] : [] update_attributes(@tasks) end
Public Instance Methods
add(title)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 32 def add(title) @tasks << Task.new({'title' => title}) store end
all()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 14 def all @tasks end
finish(id)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 37 def finish(id) @tasks.select{|task| task.id.to_s == id.to_s}.first.complete store end
remove(options)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 22 def remove(options) @tasks = @tasks.select{|task| !task.match(options)} store end
set_priority(id, priority)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 27 def set_priority(id, priority) @tasks.select{|task| task.match({id: id})}.first.priority = priority store end
sort(column = :stage)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 18 def sort(column = :stage) @tasks.sort {|a, b| a.send(column) <=> b.send(column)} if @tasks.length > 0 end
start(id)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 42 def start(id) @tasks.select{|task| task.id.to_s == id.to_s}.first.start store end
Private Instance Methods
attrs()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 76 def attrs [:title, :date_created, :stage, :priority] end
create()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 64 def create File.open(@@location, 'w+'){|f| f.puts "# .task.store"} end
store()
click to toggle source
# File lib/doneski/tasks_collection.rb, line 57 def store @store = YAML::Store.new(@@location) @store.transaction do @store['tasks'] = @tasks end end
update_attributes(tasks)
click to toggle source
# File lib/doneski/tasks_collection.rb, line 68 def update_attributes(tasks) tasks.each do |task| attrs.each do |attr| task.send((attr.to_s+"=").to_sym, '') unless task.send attr end end end