Permalink
Browse files

Refactors Pomo::List

Places complex finder logic in private method
  • Loading branch information...
1 parent bab6b48 commit 229ca52e89471d50b5d1315d2e315ee1908d6173 @stephenmckinney stephenmckinney committed Jan 27, 2013
Showing with 28 additions and 26 deletions.
  1. +28 −26 lib/pomo/list.rb
View
@@ -46,32 +46,7 @@ def initialize(opts = {})
#
def find(*args, &block)
- found = []
- found << tasks.first if args.empty?
-
- args.each do |arg|
- case arg
- when 'all'
- found = tasks
- break
- when 'first'
- found << tasks.first
- when 'last'
- found << tasks.last
- when 'complete'
- found.concat tasks.select { |task| task.complete? }
- when 'completed'
- found.concat tasks.select { |task| task.complete? }
- when 'incomplete'
- found.concat tasks.select { |task| not task.complete? }
- when /^(\d+)$/
- found << tasks[$1.to_i]
- when /^(\d+)\.\.(-?\d+)$/
- found.concat tasks[$1.to_i..$2.to_i]
- end
- end
-
- found.compact!
+ found = find_tasks(args)
if block.arity == 2
found.each_with_index do |task, i|
@@ -126,6 +101,33 @@ def load
private
+ def find_tasks(args)
+ found = []
+ found << tasks.first if args.empty?
+
+ args.each do |arg|
+ case arg
+ when 'all'
+ found = tasks
+ break
+ when 'first'
+ found << tasks.first
+ when 'last'
+ found << tasks.last
+ when 'complete', 'completed'
+ found.concat tasks.select { |task| task.complete? }
+ when 'incomplete'
+ found.concat tasks.select { |task| not task.complete? }
+ when /^(\d+)$/
+ found << tasks[$1.to_i]
+ when /^(\d+)\.\.(-?\d+)$/
+ found.concat tasks[$1.to_i..$2.to_i]
+ end
+ end
+
+ found.compact
+ end
+
def index(arg)
case arg
when 'first'

0 comments on commit 229ca52

Please sign in to comment.