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 79 79: def <<(entry) 80: @entries << entry 81: @sorted = false 82: end
Return the index-th entry.
# File lib/Journal.rb, line 93 93: def[](index) 94: sort! 95: @entries[index] 96: end
Return the number of entries.
# File lib/Journal.rb, line 74 74: def count 75: @entries.length 76: end
The well known iterator. The list will be sorted first.
# File lib/Journal.rb, line 99 99: def each 100: sort! 101: @entries.each do |entry| 102: yield entry 103: end 104: end
Like Array::empty?
# File lib/Journal.rb, line 107 107: def empty? 108: @entries.empty? 109: end
Like Array::include?
# File lib/Journal.rb, line 112 112: def include?(entry) 113: @entries.include?(entry) 114: 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 121 121: def last(date = nil) 122: result = [] 123: sort! 124: # If we have no date, return the latest entry. 125: return [ @entries.last ] unless date 126: 127: @entries.reverse_each do |e| 128: if result.empty? 129: result << e if e.date <= date 130: elsif result.first.date == e.date 131: result << e 132: else 133: break 134: end 135: end 136: result 137: 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 141 141: def sort! 142: if block_given? 143: @entries.sort! { |a, b| yield(a, b) } 144: else 145: return if @sorted 146: 147: @entries.sort! { |a, b| a.date != b.date ? 148: a.date <=> b.date : 149: (a.alertLevel != b.alertLevel ? 150: a.alertLevel <=> b.alertLevel : 151: a.property.sequenceNo <=> 152: b.property.sequenceNo) } 153: end 154: @sorted = true 155: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.