Sha256: 06a915dcd4f13e4b2f28801d2b38f3cb7e3c0de1b9489145307657959dc34487

Contents?: true

Size: 698 Bytes

Versions: 37

Compression:

Stored size: 698 Bytes

Contents

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

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
ramaze-2023.01.06 examples/app/chat/model/history.rb
Pistos-ramaze-2009.04.08 examples/app/chat/model/history.rb
Pistos-ramaze-2009.06.12 examples/app/chat/model/history.rb
manveru-ramaze-2009.04.01 examples/app/chat/model/history.rb
manveru-ramaze-2009.04.08 examples/app/chat/model/history.rb
manveru-ramaze-2009.04.18 examples/app/chat/model/history.rb
manveru-ramaze-2009.04.22 examples/app/chat/model/history.rb
manveru-ramaze-2009.04 examples/app/chat/model/history.rb
manveru-ramaze-2009.05.08 examples/app/chat/model/history.rb
manveru-ramaze-2009.05 examples/app/chat/model/history.rb
manveru-ramaze-2009.06.04 examples/app/chat/model/history.rb
manveru-ramaze-2009.06.12 examples/app/chat/model/history.rb
manveru-ramaze-2009.06 examples/app/chat/model/history.rb
manveru-ramaze-2009.07 examples/app/chat/model/history.rb
rjspotter-ramaze-2009.06.29 examples/app/chat/model/history.rb
rjspotter-ramaze-2009.06.31 examples/app/chat/model/history.rb
ramaze-2012.12.08 examples/app/chat/model/history.rb
ramaze-2012.12.08b examples/app/chat/model/history.rb
ramaze-2012.04.14 examples/app/chat/model/history.rb
ramaze-2012.03.07 examples/app/chat/model/history.rb