Sha256: 68eb4c27c037775177da252ba90ad434a69114d75c0b5b3cec8b4ebca39bb2d3
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module USaidWat module CLI class PostFormatter < BaseFormatter def format(post) cols = tty.width out = StringIO.new out.write("\n\n\n") unless @count == 0 out.write("#{post.subreddit}\n".color(:green)) out.write("#{post_link(post)}\n".color(:yellow)) out.write("#{post.title.strip.unescape_html.truncate(cols)}\n".color(:magenta)) out.write("#{post_date(post)}".color(:blue)) out.write("\n#{post.url}") unless post.url.end_with?(post.permalink) @count += 1 out.rewind out.read end private def post_link(post) "https://www.reddit.com#{post.permalink.split('/')[0..-2].join('/')}" end def post_date(post) post.created_utc.ago end end class CompactPostFormatter < BaseFormatter def format(post) cols = tty.width out = StringIO.new subreddit = post.subreddit cols -= subreddit.length + 1 title = post.title.strip.unescape_html.truncate(cols) out.write(subreddit.color(:green)) out.write(" #{title}\n") out.rewind out.read end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
usaidwat-1.5.0 | lib/usaidwat/formatter/post.rb |