Sha256: b39f1283891dd9ed9af0c94635a5918b18276831dbec992806bec8b64fe6ba2b

Contents?: true

Size: 646 Bytes

Versions: 2

Compression:

Stored size: 646 Bytes

Contents

module Tw::App
  class Render
    def self.color_code(str)
      colors = Sickill::Rainbow::TERM_COLORS.keys - [:default, :black, :white]
      n = str.each_byte.map{|c| c.to_i}.inject{|a,b|a+b}
      return colors[n%colors.size]
    end
    
    def self.display(arr)
      arr = [arr] unless arr.kind_of? Array
      arr.flatten.sort{|a,b|
        a[:id] <=> b[:id]
      }.uniq.each{|m|
        user = m[:user].kind_of?(Hash) ? "@#{m[:user][:from]} > @#{m[:user][:to]}" : "@#{m[:user]}"
        line = "#{m[:time].strftime '[%m/%d %a] (%H:%M:%S)'} #{user} : #{m[:text]}"
        puts line.colorize(/@[a-zA-Z0-9_]+/)
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tw-0.2.1 lib/tw/app/render.rb
tw-0.2.0 lib/tw/app/render.rb