class Ayadn::Search

Public Class Methods

new(api, view, workers) click to toggle source
# File lib/ayadn/search.rb, line 6
def initialize api, view, workers
  @api = api
  @view = view
  @workers = workers
end

Public Instance Methods

find(words, options) click to toggle source
# File lib/ayadn/search.rb, line 29
def find(words, options)
  Settings.options.timeline.compact = true if options[:compact]
  Settings.global.force = true if options[:force]
  @view.downloading(options)
  stream = get_stream(words, options)
  if options[:users]
    stream_object = stream["data"].map { |user| UserObject.new(user) }
  elsif !options[:channels]
    stream_object = StreamObject.new(stream)
  end
  if options[:users]
    get_users(stream_object, options)
  elsif options[:channels]
    get_channels(stream, options)
  else
    get_generic(stream_object, words, options)
  end
  if Settings.options.timeline.compact && !options[:raw]
    puts "\n" 
  end
end
hashtag(hashtag, options) click to toggle source
# File lib/ayadn/search.rb, line 12
def hashtag(hashtag, options)
  Settings.options.timeline.compact = true if options[:compact]
  Settings.global.force = true if options[:force]
  @view.downloading(options)
  stream = @api.get_hashtag(hashtag)
  stream_object = StreamObject.new(stream)
  Check.new.no_data(stream_object, 'hashtag')
  if options[:extract]
    @view.all_hashtag_links(stream_object, hashtag)
  else
    @view.render(stream_object, options)
    if Settings.options.timeline.compact && !options[:raw]
      puts "\n" 
    end
  end
end

Private Instance Methods

get_channels(stream, options) click to toggle source
# File lib/ayadn/search.rb, line 78
def get_channels stream, options
  stream_object = stream["data"].map { |ch| ChannelObject.new(ch) }
  @view.show_channels(stream_object, options)
end
get_generic(stream, words, options) click to toggle source
# File lib/ayadn/search.rb, line 70
def get_generic stream, words, options
  if options[:extract]
    @view.all_search_links(stream, words)
  else
    @view.render(stream, options)
  end
end
get_stream(words, options) click to toggle source
# File lib/ayadn/search.rb, line 53
def get_stream words, options
  if options[:users]
    @api.search_users words, options
  elsif options[:annotations]
    @api.search_annotations words, options
  elsif options[:channels]
    @api.search_channels words, options
  elsif options[:messages]
    words = words.split(',')
    channel_id = @workers.get_channel_id_from_alias(words[0])
    words.shift
    @api.search_messages channel_id, words.join(','), options
  else
    @api.get_search words, options
  end
end
get_users(stream, options) click to toggle source
# File lib/ayadn/search.rb, line 83
def get_users stream, options
  sorted = stream.sort_by {|obj| obj.counts.followers}
  sorted.each do |obj|
    puts @view.big_separator unless Settings.options.timeline.compact
    @view.show_userinfos(obj, nil, false)
  end
  puts "\n" if Settings.options.timeline.compact
end