Class: Tw::App::Render
- Inherits:
-
Object
- Object
- Tw::App::Render
- Defined in:
- lib/tw/app/render.rb
Class Method Summary collapse
- .color_code(str) ⇒ Object
- .display(arr, format) ⇒ Object
- .puts(s) ⇒ Object
- .show_status_id ⇒ Object
- .show_status_id=(bool) ⇒ Object
- .silent ⇒ Object
- .silent=(bool) ⇒ Object
Class Method Details
.color_code(str) ⇒ Object
24 25 26 27 28 |
# File 'lib/tw/app/render.rb', line 24 def self.color_code(str) colors = Rainbow::Color::Named::NAMES.keys - [:default, :black, :white] n = str.each_byte.map{|c| c.to_i}.inject{|a,b|a+b} return colors[n%colors.size] end |
.display(arr, format) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tw/app/render.rb', line 30 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.fav_count}Fav" if m.fav_count.to_i > 0 line += " #{m.rt_count}RT" if m.rt_count.to_i > 0 line += " <#{m.id}>" if show_status_id line.colorize(/@[a-zA-Z0-9_]+|\d+RT|\d+Fav/) when 'json' m.to_json else m.format format end } end |
.puts(s) ⇒ Object
20 21 22 |
# File 'lib/tw/app/render.rb', line 20 def self.puts(s) STDOUT.puts s unless silent end |
.show_status_id ⇒ Object
16 17 18 |
# File 'lib/tw/app/render.rb', line 16 def self.show_status_id @@show_status_id ||= false end |
.show_status_id=(bool) ⇒ Object
12 13 14 |
# File 'lib/tw/app/render.rb', line 12 def self.show_status_id=(bool) @@show_status_id = bool ? true : false end |
.silent ⇒ Object
8 9 10 |
# File 'lib/tw/app/render.rb', line 8 def self.silent @@silent ||= false end |
.silent=(bool) ⇒ Object
4 5 6 |
# File 'lib/tw/app/render.rb', line 4 def self.silent=(bool) @@silent = bool ? true : false end |