class Trendious::Application

Public Class Methods

new() click to toggle source
# File lib/trendious/application.rb, line 5
def initialize
  @client = Trendious::Client.new
  @options = {}
end

Public Instance Methods

run() click to toggle source
# File lib/trendious/application.rb, line 10
def run
  OptionParser.new do |opts|
    opts.banner = "Usage: trendious [options]"
    opts.on("-q", "--query [String]", String, "Search by name") {|o| @options[:query] = o }
    opts.on("-R", "--read [Integer]", Integer, "Read entry with index") {|o| @options[:read] = o }
    opts.on("-p", "--page [Integer]", Integer, "Select N page") {|o| @options[:page] = o }
    opts.on("-T", "--tags", "Show tags") {|o| @options[:tags] = o }
    opts.on("-t", "--trending [Integer]", Integer, "Select trending by index") {|o| @options[:trending] = o}
    opts.on("-v", "--version", "Display current Trendious version") {|o| @options[:version] = o }
  end.parse!

  puts output
end

Private Instance Methods

output() click to toggle source
# File lib/trendious/application.rb, line 44
def output
  return Trendious::VERSION if @options[:version]
  if @options[:tags]
    return read_entry(tags[@options[:trending]].trending(@options[:page]).entries[@options[:read]]) if @options[:read]
    return tags[@options[:trending]].trending(@options[:page]).entries.each_with_index.map{|p,idx| "[#{idx}] #{p.title}" } if @options[:trending]
    tags.each_with_index.map{|tag, idx| "[#{idx}] #{tag.name}" }
  elsif @options[:query]
    return read_entry(posts[@options[:read]]) if @options[:read]
    posts.each_with_index.map{|p,idx| "[#{idx}] #{p.name}" }
  end
end
posts() click to toggle source
# File lib/trendious/application.rb, line 30
def posts
  @client.posts_by_name(@options[:query], @options[:page]).entries
end
read_entry(entry_by_idx) click to toggle source
# File lib/trendious/application.rb, line 34
def read_entry(entry_by_idx)
  entry = entry_by_idx.read

  body = entry["body"] || entry["html_body"]

  entry["title"] + "\n" +
  "Website link: #{entry_by_idx.link}\n\n" +
  body.gsub!(/<.*?>/, " ")
end
tags() click to toggle source
# File lib/trendious/application.rb, line 26
def tags
  @client.tags.entries
end