Permalink
Browse files

code cleanup

  • Loading branch information...
1 parent 1529247 commit d6cecde742ad4392b0e31ca7fd59ffec8b879067 @mariusgrigoriu committed Oct 3, 2011
Showing with 14 additions and 9 deletions.
  1. +6 −5 bin/milkmaid
  2. +8 −4 lib/milkmaid.rb
View
@@ -19,25 +19,26 @@ Main {
def run
begin
milkmaid.incomplete_tasks.each_with_index do |taskseries, i|
+ task = Milkmaid::last_task taskseries
text = "#{i+1}: #{taskseries['name']}"
text << "(R)" unless taskseries['rrule'].nil?
- text << " #{Time.parse(taskseries['task'].as_array.last['due']).getlocal.strftime(
- "%A %b %d, %Y %I:%M %p")}" unless taskseries['task'].as_array.last['due'].empty?
+ text << " #{Time.parse(Milkmaid::last_task(taskseries)['due']).getlocal.strftime(
+ "%A %b %d, %Y %I:%M %p")}" unless task['due'].empty?
color = {
'1'=>[234, 82, 0],
'2'=>[0, 96, 191],
'3'=>[53, 154, 255],
'N'=>:nothing
}
mode1 = mode2 = nil
- case Date.today <=> Date.parse(taskseries['task'].as_array.last['due'])
+ case Date.today <=> Date.parse(task['due'])
when 0
mode1 = :bold
when 1
mode1 = :bold
mode2 = :underline
- end unless taskseries['task'].as_array.last['due'].empty?
- puts Paint[text, color[taskseries['task'].as_array.last['priority']], mode1, mode2]
+ end unless task['due'].empty?
+ puts Paint[text, color[task['priority']], mode1, mode2]
end
rescue RTM::NoTokenException
puts "Authentication token not found. Run `#{__FILE__} auth start`"
View
@@ -23,13 +23,13 @@ def incomplete_tasks
if !items['taskseries'].nil?
items['taskseries'].as_array.each do |taskseries|
taskseries['list_id'] = list_id
- entries << taskseries if taskseries['task'].as_array.last['completed'].empty?
+ entries << taskseries if Milkmaid::last_task(taskseries)['completed'].empty?
end
end
end
entries.sort! do |a, b|
- taska = a['task'].as_array.last
- taskb = b['task'].as_array.last
+ taska = Milkmaid::last_task a
+ taskb = Milkmaid::last_task b
result = taska['priority'] <=> taskb['priority']
if result == 0
if taska['due'].empty?
@@ -46,7 +46,7 @@ def incomplete_tasks
entries.each_with_index do |taskseries, i|
@config["#{i+1}list_id"] = taskseries['list_id']
@config["#{i+1}taskseries_id"] = taskseries['id']
- @config["#{i+1}task_id"] = taskseries['task'].as_array.last['id']
+ @config["#{i+1}task_id"] = Milkmaid::last_task(taskseries)['id']
end
save_config
entries
@@ -81,6 +81,10 @@ def auth_finish
class TaskNotFound < StandardError
end
+ def self.last_task(taskseries)
+ taskseries['task'].as_array.last
+ end
+
private
def save_config
File.open(@config_file, 'w') { |f| YAML.dump(@config, f) }

0 comments on commit d6cecde

Please sign in to comment.