C0 code coverage information
Generated on Mon Feb 11 21:39:28 +0100 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
lib/dst.rb
|
63
|
56
|
|
|
1 require 'rubygems'
2 require 'dst/models'
3
4 class Dst
5 include Models
6
7 def self.process_command(command)
8 new.process_command(command)
9 end
10
11 def process_command(command)
12 options = extract_options_from_command(command)
13 if command.blank? || !options.has_key?(:description)
14 list_tasks(options)
15 elsif command =~ /^\^(\d+)$/
16 toggle_task($1.to_i)
17 else
18 create_task(options)
19 end
20 end
21
22 def create_task(options={})
23 task = Task.new(:description => options[:description])
24 task.context = Context.find_or_create_by_name(options[:context]) if options.has_key?(:context)
25 task.project = Project.find_or_create_by_name(options[:project]) if options.has_key?(:project)
26 task.save
27 puts "`#{task}' created."
28 end
29
30 def toggle_task(task_id)
31 task = Task.toggle!(task_id)
32 puts "Ok, `#{task}' marked as `#{task.status}'."
33 rescue ActiveRecord::RecordNotFound
34 puts "Oops, task ##{task_id} not found."
35 end
36
37 def list_tasks(options={}, include_completed=false)
38 context, project = options.values_at(:context, :project)
39 tasks = if options.empty?
40 Task.unfinished
41 elsif context
42 Task.unfinished.select { |task|
43 task.context.name == context if task.context
44 }
45 elsif project
46 Task.unfinished.select { |task|
47 task.project.name == project if task.project
48 }
49 end || []
50 puts tasks.empty? ? 'No tasks found' : tasks.map(&:to_s).join("\n")
51 end
52
53 protected
54 def extract_options_from_command(command)
55 context = command =~ /^@(\w+)/ && $1
56 project = command =~ /(?!\w):(\w+)/ && $1
57 description = command.dup
58 description.gsub!("@#{context}", '') unless context.nil?
59 description.gsub!(":#{project}", '') unless project.nil?
60 options = {:context => context, :project => project, :description => description.strip}
61 options.reject { |k, v| v.nil? || v.blank? }
62 end
63 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.