The JournalEntryList is an Array with a twist. Before any data retrieval function is called, the list of JournalEntry objects will be sorted by date. This is a utility class only. Use Journal to store a journal.
Add a list of JournalEntry objects to the existing list. The list will be marked unsorted.
# File lib/Journal.rb, line 85 85: def +(list) 86: @entries + list 87: end
Add a new JournalEntry to the list. The list will be marked as unsorted.
# File lib/Journal.rb, line 78 78: def <<(entry) 79: @entries << entry 80: @sorted = false 81: end
Return the index-th entry.
# File lib/Journal.rb, line 90 90: def[](index) 91: sort 92: @entries[index] 93: end
Return the number of entries.
# File lib/Journal.rb, line 73 73: def count 74: @entries.length 75: end
The well known iterator. The list will be sorted first.
# File lib/Journal.rb, line 96 96: def each 97: sort 98: @entries.each do |entry| 99: yield entry 100: end 101: end
Like Array::include?
# File lib/Journal.rb, line 104 104: def include?(entry) 105: @entries.include?(entry) 106: end
Returns the last elements (by date) if date is nil or the last elements right before the given date. If there are multiple entries with exactly the same date, all are returned. Otherwise the result Array will only contain one element. In case no matching entry is found, the Array will be empty.
# File lib/Journal.rb, line 113 113: def last(date = nil) 114: result = [] 115: sort 116: # If we have no date, return the latest entry. 117: return [ @entries.last ] unless date 118: 119: @entries.reverse_each do |e| 120: if result.empty? 121: result << e if e.date <= date 122: elsif result.first.date == e.date 123: result << e 124: else 125: break 126: end 127: end 128: result 129: end
Sort the list of entries. First by ascending by date, than by alertLevel and finally by PropertyTreeNode sequence number.
# File lib/Journal.rb, line 135 135: def sort 136: return if @sorted 137: 138: @entries.sort! { |a, b| a.date != b.date ? 139: a.date <=> b.date : 140: (a.alertLevel != b.alertLevel ? 141: a.alertLevel <=> b.alertLevel : 142: a.property.sequenceNo <=> 143: b.property.sequenceNo) } 144: @sorted = true 145: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.