Parent

Class Index [+]

Quicksearch

TaskJuggler::JournalEntryList

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.

Attributes

entries[R]

Public Class Methods

new() click to toggle source
    # File lib/taskjuggler/Journal.rb, line 73
73:     def initialize
74:       @entries = []
75:       @sorted = false
76:     end

Public Instance Methods

+(list) click to toggle source

Add a list of JournalEntry objects to the existing list. The list will be marked unsorted.

    # File lib/taskjuggler/Journal.rb, line 91
91:     def +(list)
92:       @entries += list.entries
93:       @sorted = false
94:       self
95:     end
<<(entry) click to toggle source

Add a new JournalEntry to the list. The list will be marked as unsorted.

    # File lib/taskjuggler/Journal.rb, line 84
84:     def <<(entry)
85:       @entries << entry
86:       @sorted = false
87:     end
[](index) click to toggle source

Return the index-th entry.

     # File lib/taskjuggler/Journal.rb, line 98
 98:     def[](index)
 99:       sort!
100:       @entries[index]
101:     end
count() click to toggle source

Return the number of entries.

    # File lib/taskjuggler/Journal.rb, line 79
79:     def count
80:       @entries.length
81:     end
delete_if() click to toggle source

Like Array::delete_if

     # File lib/taskjuggler/Journal.rb, line 112
112:     def delete_if
113:       @entries.delete_if { |e| yield(e) }
114:     end
each() click to toggle source

The well known iterator. The list will be sorted first.

     # File lib/taskjuggler/Journal.rb, line 104
104:     def each
105:       sort!
106:       @entries.each do |entry|
107:         yield entry
108:       end
109:     end
empty?() click to toggle source

Like Array::empty?

     # File lib/taskjuggler/Journal.rb, line 117
117:     def empty?
118:       @entries.empty?
119:     end
first() click to toggle source

Like Array::first but list is first sorted.

     # File lib/taskjuggler/Journal.rb, line 132
132:     def first
133:       sort!
134:       @entries.first
135:     end
include?(entry) click to toggle source

Like Array::include?

     # File lib/taskjuggler/Journal.rb, line 127
127:     def include?(entry)
128:       @entries.include?(entry)
129:     end
last(date = nil) click to toggle source

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/taskjuggler/Journal.rb, line 142
142:     def last(date = nil)
143:       result = JournalEntryList.new
144:       sort!
145: 
146:       @entries.reverse_each do |e|
147:         if result.empty?
148:           # We haven't found any yet. So add the first one we find before the
149:           # cut-off date.
150:           result << e if e.date <= date
151:         elsif result.first.date == e.date
152:           # Now we only accept other entries with the exact same date.
153:           result << e
154:         else
155:           # We've found all entries we are looking for.
156:           break
157:         end
158:       end
159:       result.sort!
160:     end
length() click to toggle source

Like Array:length

     # File lib/taskjuggler/Journal.rb, line 122
122:     def length
123:       @entries.length
124:     end
sort!() click to toggle source

Sort the list of entries. First by ascending by date, than by alertLevel and finally by PropertyTreeNode sequence number.

     # File lib/taskjuggler/Journal.rb, line 164
164:     def sort!
165:       if block_given?
166:         @entries.sort! { |a, b| yield(a, b) }
167:       else
168:         return self if @sorted
169: 
170:         @entries.sort! { |a, b| a.date != b.date ?
171:                                 a.date <=> b.date :
172:                                 (a.alertLevel != b.alertLevel ?
173:                                  a.alertLevel <=> b.alertLevel :
174:                                  a.property.sequenceNo <=>
175:                                  b.property.sequenceNo) }
176:       end
177:       @sorted = true
178:       self
179:     end
uniq!() click to toggle source

Eliminate duplicate entries.

     # File lib/taskjuggler/Journal.rb, line 182
182:     def uniq!
183:       @entries.uniq!
184:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.