/usr/share/doc/ruby-ramaze/examples/app/chat/model/history.rb is in ruby-ramaze 2012.12.08-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | require 'ramaze/gestalt'
class History
def initialize(size = 13)
@size = size
@history = []
end
def write(nick, text)
text.strip!
return if text.empty?
@history.shift until @history.size < @size
@history << Message.new(nick, text, Time.now)
true
end
def to_html
g = Ramaze::Gestalt.new
each do |message|
g.div(:class => :message) do
g.span(:class => :time){ message[:time].strftime('%X') }
g.span(:class => :nick){ message[:nick] }
g.span(:class => :text){ message[:text] }
end
end
g.to_s
end
include Enumerable
def each
@history.sort.each do |message|
yield message
end
end
end
|