Sha256: 747cb4e40a7034bf6c98469d62b0456d29aec3d52b8c65603a23aa212ef2d17c

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

module Tw::App
  class Render

    def self.silent=(bool)
      @@silent = bool ? true : false
    end

    def self.silent
      @@silent ||= false
    end

    def self.show_status_id=(bool)
      @@show_status_id = bool ? true : false
    end

    def self.show_status_id
      @@show_status_id ||= false
    end

    def self.puts(s)
      STDOUT.puts s unless silent
    end

    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, format)
      arr = [arr] unless arr.kind_of? Array
      arr.flatten.inject({}){
        |h,i| h[i.id]=i; h
      }.values.sort{|a,b|
        a.id <=> b.id
      }.each{|m|
        STDOUT.puts case format
                    when 'text'
                      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} : #{CGI.unescapeHTML m.text}"
                      line += " <#{m.id}>" if show_status_id
                      line.colorize(/@[a-zA-Z0-9_]+/)
                    when 'json'
                      m.to_json
                    else
                      m.format format
                    end
      }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tw-0.4.7 lib/tw/app/render.rb
tw-0.4.6 lib/tw/app/render.rb
tw-0.4.5 lib/tw/app/render.rb
tw-0.4.4 lib/tw/app/render.rb
tw-0.4.3 lib/tw/app/render.rb
tw-0.4.2 lib/tw/app/render.rb
tw-0.4.1 lib/tw/app/render.rb
tw-0.4.0 lib/tw/app/render.rb