Class: AsciiTracker::Model
- Inherits:
-
Object
- Object
- AsciiTracker::Model
- Defined in:
- lib/asciitracker/model.rb
Instance Attribute Summary collapse
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #add_record(rec, date = Date.today) ⇒ Object
- #by_date(date) ⇒ Object
- #find_best_cover(rec, date = Date.today) ⇒ Object
- #find_overlaps(rec, date = Date.today) ⇒ Object
-
#initialize ⇒ Model
constructor
A new instance of Model.
Constructor Details
Instance Attribute Details
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
4 5 6 |
# File 'lib/asciitracker/model.rb', line 4 def projects @projects end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
4 5 6 |
# File 'lib/asciitracker/model.rb', line 4 def records @records end |
Instance Method Details
#add_record(rec, date = Date.today) ⇒ Object
16 17 18 19 20 |
# 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) ⇒ Object
12 13 14 |
# File 'lib/asciitracker/model.rb', line 12 def by_date(date) (@by_date[date] ||= []) end |
#find_best_cover(rec, date = Date.today) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
22 23 24 |
# 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 |