Class: USaidWat::CLI::CommentFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/usaidwat/formatter/comment.rb

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize, #pattern, #pattern?, #raw?, #relative_dates?

Methods included from TTYFormatter

#tty

Constructor Details

This class inherits a constructor from USaidWat::CLI::BaseFormatter

Instance Method Details

#format(comment) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/usaidwat/formatter/comment.rb', line 4

def format(comment)
  cols = tty.width
  out = StringIO.new
  out.write("\n\n") unless @count == 0
  out.write("#{comment.subreddit}\n".color(:green))
  out.write("#{comment_link(comment)}\n".color(:yellow))
  out.write("#{comment.link_title.strip.unescape_html.truncate(cols)}\n".color(:magenta))
  out.write("#{comment_date(comment)}".color(:blue))
  out.write(" \u2022 ".color(:cyan))
  out.write(sprintf("%+d\n", comment_karma(comment)).color(:blue))
  out.write("\n")
  out.write("#{comment_body(comment)}\n")
  @count += 1
  out.rewind
  out.read
end