Sha256: 805b8d599ab17959f281381f1c64535acfa42e899525b5cbeb638f0e3c3e2218

Contents?: true

Size: 687 Bytes

Versions: 17

Compression:

Stored size: 687 Bytes

Contents

class History
  include Ramaze::Helper::CGI

  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(h(nick), h(text), Time.now)
    true
  end

  def to_html
    @history.map {|message|
      '<div class="message">' <<
          [:time, :nick, :text].map{|key| span_for(message, key)}.join("\n") <<
      '</div>'
    }.join("\n")
  end

  def span_for(message, key)
    "<span class='#{key}'>#{message[key]}</span>"
  end

  include Enumerable

  def each
    @history.sort.each do |message|
      yield message
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
Pistos-ramaze-2008.09 examples/app/chat/model/history.rb
Pistos-ramaze-2008.12 examples/app/chat/model/history.rb
Pistos-ramaze-2009.01 examples/app/chat/model/history.rb
Pistos-ramaze-2009.02 examples/app/chat/model/history.rb
manveru-ramaze-2008.07 examples/app/chat/model/history.rb
manveru-ramaze-2008.08 examples/app/chat/model/history.rb
manveru-ramaze-2008.09 examples/app/chat/model/history.rb
manveru-ramaze-2008.10 examples/app/chat/model/history.rb
manveru-ramaze-2008.12 examples/app/chat/model/history.rb
manveru-ramaze-2009.01 examples/app/chat/model/history.rb
ptomato-ramaze-2009.02.1 examples/app/chat/model/history.rb
ptomato-ramaze-2009.02 examples/app/chat/model/history.rb
ramaze-2008.06 examples/app/chat/model/history.rb
ramaze-2009.01 examples/app/chat/model/history.rb
ramaze-2008.11 examples/app/chat/model/history.rb
ramaze-2009.03 examples/app/chat/model/history.rb
ramaze-2009.02 examples/app/chat/model/history.rb