Skip to content

Commit

Permalink
getting initial command 'tasks' working
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed Jun 16, 2008
1 parent 43033d7 commit bbf2ddd
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 25 deletions.
9 changes: 9 additions & 0 deletions lib/core_ext/datetime.rb
@@ -0,0 +1,9 @@
require 'date'

class DateTime

def blank?
false
end

end
11 changes: 1 addition & 10 deletions lib/core_ext/enumerable.rb
@@ -1,16 +1,7 @@
module Enumerable

def path_lookup(path)
value = self
parts = path.to_s.split('/')
parts.each do |part|
value = hash[part]
end
value
end

def sorted_by(attribute)
self.sort_by { |e| e.path_lookup(attribute) }
self.sort_by { |e| e[attribute] }
end

end
7 changes: 7 additions & 0 deletions lib/core_ext/nil.rb
@@ -0,0 +1,7 @@
class NilClass

def blank?
true
end

end
8 changes: 8 additions & 0 deletions lib/core_ext/string.rb
@@ -1,7 +1,11 @@
require 'date'
require 'rubygems'
require 'term/ansicolor'

class String

include Term::ANSIColor

def to_date
begin
date = DateTime.parse(self)
Expand All @@ -11,4 +15,8 @@ def to_date
date
end

def blank?
self == ""
end

end
4 changes: 4 additions & 0 deletions lib/remember-the-ruby/api.rb
Expand Up @@ -35,6 +35,10 @@ def tasks

# derivative objects ######################################################

def default_list
lists.find(settings["defaultlist"])
end

def tags
found_tags = EntityList.new(@transport, Tag)
tasks.each do |task|
Expand Down
11 changes: 11 additions & 0 deletions lib/remember-the-ruby/entity.rb
Expand Up @@ -34,6 +34,17 @@ def [](key)
def []=(key, value)
regular_writer(key.to_s, value)
end

alias_method :original_lookup, :[]

def [](key)
value = self
parts = key.to_s.split('/')
parts.each do |part|
value = value.original_lookup(part)
end
value
end

end
end
2 changes: 1 addition & 1 deletion lib/remember-the-ruby/entity_list.rb
Expand Up @@ -53,6 +53,6 @@ def self.from_rsp(transport, type, rsp, xpath)
end
entity_list
end

end
end
28 changes: 16 additions & 12 deletions lib/rtr/api.rb
@@ -1,18 +1,22 @@
def api_connection
def api

api = RememberTheRuby::API.new(:frob => $storage[:frob],
:token => $storage[:token])
@api ||= begin

unless $storage[:frob]
system %{open "#{api.authorization_url}"}
$storage[:frob] = api.frob
exit
end
api = RememberTheRuby::API.new(:frob => $storage[:frob],
:token => $storage[:token])

unless $storage[:token]
$storage[:token] = api.authenticate
end
unless $storage[:frob]
system %{open "#{api.authorization_url}"}
$storage[:frob] = api.frob
exit
end

unless $storage[:token]
$storage[:token] = api.authenticate
end

api
api

end

end
30 changes: 28 additions & 2 deletions lib/rtr/commands.rb
@@ -1,9 +1,35 @@
require 'term/ansicolor'

module RTR
class Commands

register_method :tasks do |options|
pp api_connection.tasks.select do |t|
t.next.due.to_date && t.next.due.to_date > DateTime.now

puts "Oustanding Tasks".white.bold
puts
api.default_list.tasks.sorted_by('next/due').reverse.each do |task|

now = DateTime.now

due = task['next/due']
due = due.to_date unless due.blank?

diff = due.blank? ? nil : due - now

color = case
when diff.nil? then :white
when diff.abs < 1 && due.day == now.day then :yellow
when diff < 0 then :red
else :white
end

title = task.name
title = title.send(color).bold if color

prefix = " * "
prefix = prefix.send(color).bold if color

puts prefix + title
end
end

Expand Down

0 comments on commit bbf2ddd

Please sign in to comment.