class AsciiTracker::Model

Attributes

projects[R]
records[R]

Public Class Methods

new() click to toggle source
# File lib/asciitracker/model.rb, line 6
def initialize 
  @records = [ ]
  @by_date = { }
  @projects = Hash.new { |hash, project_id| hash[project_id] = [] }
end

Public Instance Methods

add_record(rec, date = Date.today) click to toggle source
# File lib/asciitracker/model.rb, line 16
def add_record rec, date = Date.today
  @records.push(rec)
  (@by_date[date] ||= []).push(rec)
  rec
end
by_date(date) click to toggle source
# File lib/asciitracker/model.rb, line 12
def by_date(date)
  (@by_date[date] ||= [])
end
find_best_cover(rec, date = Date.today) click to toggle source
# File lib/asciitracker/model.rb, line 26
def find_best_cover rec, date = Date.today
  by_date(date).inject(nil) do |best, test| 
    if test.respond_to?(:covers?) # spans never cover
      if test.covers?(rec) && (best.nil? || (best.covers? test))
        best = test 
      end
    end
    best
  end
end
find_overlaps(rec, date = Date.today) click to toggle source
# File lib/asciitracker/model.rb, line 22
def find_overlaps rec, date = Date.today
  by_date(date).find_all { |a| a.overlaps?(rec) rescue false }
end