Sha256: a4f5b7739ff884f1e400f2d0bcc44a5b98b90ea0dd48d573a56360de465c4e9f
Contents?: true
Size: 672 Bytes
Versions: 1
Compression:
Stored size: 672 Bytes
Contents
module Buschtelefon class Brain attr_reader :capacity def initialize(capacity = nil) @capacity = capacity @gossip_sink = [] end def <<(gossip) @gossip_sink << gossip reorganize end def load_batch(gossips) @gossip_sink += gossips reorganize end def contains?(gossip) @gossip_sink.include?(gossip) end def to_a @gossip_sink end private def reorganize @gossip_sink.sort! { |x, y| y.created_at <=> x.created_at } @gossip_sink.uniq!(&:message) if @capacity @gossip_sink.slice!(capacity..-1) # only keep the newest end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
buschtelefon-0.5.0 | lib/buschtelefon/brain.rb |