Class: Report
Instance Method Summary collapse
-
#initialize(db = Sequel.sqlite("#{File.expand_path(File.dirname(__FILE__))}/../db/potam.db")) ⇒ Report
constructor
A new instance of Report.
- #week ⇒ Object
Methods included from Timer
Constructor Details
#initialize(db = Sequel.sqlite("#{File.expand_path(File.dirname(__FILE__))}/../db/potam.db")) ⇒ Report
Returns a new instance of Report.
7 8 9 10 11 |
# File 'lib/report.rb', line 7 def initialize(db = Sequel.sqlite("#{File.expand_path(File.dirname(__FILE__))}/../db/potam.db")) @db = db @report = Hash.new @report[:events] = Array.new end |
Instance Method Details
#week ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/report.rb', line 13 def week @report[:tasks] = @db.fetch("SELECT * FROM tasks WHERE (created_at BETWEEN #{last_mon} AND #{now}) OR id IN (SELECT task_id FROM subtasks WHERE (created_at BETWEEN #{last_mon} AND #{now}) OR (finished_at BETWEEN #{last_mon} AND #{now})) OR id IN (SELECT task_id FROM notes WHERE (created_at BETWEEN #{last_mon} AND #{now})) ORDER BY id DESC").to_a order = Array.new @report[:tasks].each{ |task| order << task[:id] } @report[:tasks].select{ |task| task[:created_at].between?(last_mon, now) }.each{ |task| to_event(task) } @db[:notes].where("created_at BETWEEN #{last_mon} AND #{now}").all.each{ |note| to_event(note) } @db[:subtasks].where("created_at BETWEEN #{last_mon} AND #{now}").all.each{ |subtask| to_event(subtask) } @db[:subtasks].where("finished_at BETWEEN #{last_mon} AND #{now}").all.each{ |subtask| to_event(subtask, :finished) } @report[:events].sort_by!{ |event| [order.index(event[:task_id]), event[:timestamp]] } return @report end |