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 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 92 92: def[](index) 93: sort! 94: @entries[index] 95: end
Return the number of entries.
# File lib/Journal.rb, line 73 73: def count 74: @entries.length 75: end
Like Array::delete_if
# File lib/Journal.rb, line 106 106: def delete_if 107: @entries.delete_if { |e| yield(e) } 108: end
The well known iterator. The list will be sorted first.
# File lib/Journal.rb, line 98 98: def each 99: sort! 100: @entries.each do |entry| 101: yield entry 102: end 103: end
Like Array::empty?
# File lib/Journal.rb, line 111 111: def empty? 112: @entries.empty? 113: end
Like Array::first but list is first sorted.
# File lib/Journal.rb, line 121 121: def first 122: sort! 123: @entries.first 124: end
Like Array::include?
# File lib/Journal.rb, line 116 116: def include?(entry) 117: @entries.include?(entry) 118: 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 131 131: def last(date = nil) 132: result = JournalEntryList.new 133: sort! 134: 135: @entries.reverse_each do |e| 136: if result.empty? 137: # We haven't found any yet. So add the first one we find before the 138: # cut-off date. 139: result << e if e.date <= date 140: elsif result.first.date == e.date 141: # Now we only accept other entries with the exact same date. 142: result << e 143: else 144: # We've found all entries we are looking for. 145: break 146: end 147: end 148: result.sort! 149: 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 153 153: def sort! 154: if block_given? 155: @entries.sort! { |a, b| yield(a, b) } 156: else 157: return self if @sorted 158: 159: @entries.sort! { |a, b| a.date != b.date ? 160: a.date <=> b.date : 161: (a.alertLevel != b.alertLevel ? 162: a.alertLevel <=> b.alertLevel : 163: a.property.sequenceNo <=> 164: b.property.sequenceNo) } 165: end 166: @sorted = true 167: self 168: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.