Skip to content
Browse files

stand alone command line app

  • Loading branch information...
1 parent 823ea18 commit 0b85538a8516bcea164c75dd1c3e361f87d315ac @cocoa committed
View
27 have_a_purpose/todo/bin/todo-done.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+task_number = ARGV.shift.to_i
+
+puts "Marking task #{task_number} as completed..."
+
+File.open('todo.txt','r') do |file|
+ File.open('todo.txt.new','w') do |new_file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = line.chomp.split(/,/)
+ if task_number == counter
+ # add complete time to selected task
+ new_file.puts "#{name},#{created},#{Time.now}"
+ puts "Task #{task_number} completed!"
+ else
+ # copy the contents untouched
+ new_file.puts "#{name},#{created},#{completed}"
+ end
+ counter += 1
+ end
+ end
+end
+
+`mv todo.txt.new todo.txt`
+
+puts "Done."
View
17 have_a_purpose/todo/bin/todo-list.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+
+File.open('todo.txt','r') do |file|
+ counter = 1
+ file.readlines.each do |line|
+ name,created,completed = line.chomp.split(/,/)
+ printf("%3d - %s\n", counter, name)
+ printf(" Created : %s\n", created)
+ unless completed.nil?
+ printf(" Completed: %s\n", completed)
+ end
+ counter += 1
+ end
+end
+
+
View
8 have_a_purpose/todo/bin/todo-new.rb 100644 → 100755
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+new_task = ARGV.shift # http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-shift
+
+File.open('todo.txt','a') do |file|
+ file.puts "#{new_task},#{Time.now}"
+ puts "Task added."
+end
View
3 have_a_purpose/todo/bin/todo.txt
@@ -0,0 +1,3 @@
+Comprar una nevera nueva,2013-06-01 17:41:41 +0200,2013-06-01 18:05:45 +0200
+Instalar la batería de repuesto,2013-06-01 17:41:57 +0200,
+Tirar al albanil por la borda,2013-06-01 17:52:48 +0200,

0 comments on commit 0b85538

Please sign in to comment.
Something went wrong with that request. Please try again.