Sha256: f1c46a8b2805ef0686d1c2c055522999cb65c242b52a942c4f6f8353ee090245
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 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}\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 out.write(subreddit.color(:green)) out.write(" #{title}\n") out.rewind out.read end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
usaidwat-1.6.1 | lib/usaidwat/formatter/post.rb |
usaidwat-1.6.0 | lib/usaidwat/formatter/post.rb |
usaidwat-1.5.1 | lib/usaidwat/formatter/post.rb |