aboutsummaryrefslogtreecommitdiff
path: root/log.rb
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-23 15:05:58 +0100
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-23 15:05:58 +0100
commitfc936f76f65db94469959883c8ef2926ff0e779b (patch)
tree7b3d64fc103abc02efdb6d000194062854409d34 /log.rb
parent6bcb17d78da2ed2df16c4d994c866dcf57ebe3f4 (diff)
new feature selecting parts of history
Diffstat (limited to 'log.rb')
-rw-r--r--log.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/log.rb b/log.rb
index 2d62090..fe0d4f5 100644
--- a/log.rb
+++ b/log.rb
@@ -33,7 +33,7 @@ class LogEntry
ret += "</a>" if link
ret += "</td>"
ret += "<td>#{@timestamp.strftime('%d.%m, %H:%M')}</td>"
- ret += "<td>#{CGI.escapeHTML(@comment)}</td>"
+ ret += "<td class='historycomment'>#{CGI.escapeHTML(@comment)}</td>"
ret += "</tr>"
ret
end
@@ -89,6 +89,12 @@ class Log
def each
@log.each{|e| yield(e)}
end
+ def collect
+ @log.collect{|e| yield(e)}
+ end
+ def comment_matches(regex)
+ Log.new(@log.collect{|e| e if e.comment =~ regex}.compact)
+ end
end
if __FILE__ == $0
@@ -97,16 +103,19 @@ require "test/unit"
def test_indexes
l = Log.new
- l.add(10,Time.now,"foo 10")
+ l.add(10,Time.now,"baz 10")
20.times{|i|
l.add(i,Time.now,"foo #{i}") unless i == 10
}
assert_equal(0,l.min.rev)
assert_equal(19,l.max.rev)
- assert_equal("foo 10",l[10].comment)
- l = l[9..11]
- assert_equal([9,10,11],[l[9].rev,l[10].rev,l[11].rev])
+ assert_equal("baz 10",l[10].comment)
+
+ p = l[9..11]
+ assert_equal([9,10,11],[p[9].rev,p[10].rev,p[11].rev])
+
+ assert_equal([10],l.comment_matches(/^baz \d*$/).collect{|e| e.rev})
end
end
end