lib/tw/app/render.rb in tw-0.2.4 vs lib/tw/app/render.rb in tw-0.2.5
- old
+ new
@@ -5,17 +5,24 @@
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)
+ def self.display(arr, format)
arr = [arr] unless arr.kind_of? Array
arr.flatten.sort{|a,b|
- a[:id] <=> b[:id]
+ 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} : #{CGI.unescapeHTML m[:text]}"
- puts line.colorize(/@[a-zA-Z0-9_]+/)
+ 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.colorize(/@[a-zA-Z0-9_]+/)
+ when 'json'
+ m.to_json
+ else
+ m.to_s format
+ end
}
end
end
end