module RandomYouTube

Constants

ACC_CHARS
REQUESTOR
THREE_WORDS
VERSION

Attributes

mywords[R]

Public Class Methods

human() click to toggle source
# File lib/randomyoutube.rb, line 31
def self.human
  page = local_exec
  puts "Your search results for: #{@mywords.join(', ')}"
  if page.at('openSearch|totalResults').text.to_i > 0
    puts "Title: #{page.css('entry title').first.text}"
    puts "Link: #{page.css('entry link').first['href']}"
  else
    puts "There are no results for your search."
  end
end
human_must() click to toggle source
# File lib/randomyoutube.rb, line 60
def self.human_must
  output = pretty while output == nil
  puts output
end
local_exec() click to toggle source
# File lib/randomyoutube.rb, line 18
def self.local_exec
  @mywords = `#{THREE_WORDS}`
  if $? != 0
    puts "Please make sure you have a dictionary file."
    puts "sudo apt-get install --reinstall wamerican"
    puts "Error! '#{THREE_WORDS}' failed.\nSet RandomYouTube::THREE_WORDS to a valid shell script for random words."
    Kernel.exit
  end
  @mywords = @mywords.strip_byac(ACC_CHARS).split("\n")
  urlsearch = REQUESTOR + @mywords.join('+')
  Nokogiri::XML(open(urlsearch))
end
pretty() click to toggle source
# File lib/randomyoutube.rb, line 42
def self.pretty
  page = local_exec
  if page.at('openSearch|totalResults').text.to_i > 0
    return ["Your search results for: #{@mywords.join(', ')}", "Title: #{page.css('entry title').first.text}", "Link: #{page.css('entry link').first['href']}"]
  else
    return nil
  end
end
pretty_must() click to toggle source
# File lib/randomyoutube.rb, line 65
def self.pretty_must
  output = pretty while output == nil
  return output
end
raw() click to toggle source
# File lib/randomyoutube.rb, line 51
def self.raw
  page = local_exec
  if page.at('openSearch|totalResults').text.to_i > 0
    return [@mywords.join(', '), page.css('entry title').first.text, page.css('entry link').first['href']]
  else
    return nil
  end
end
raw_must() click to toggle source
# File lib/randomyoutube.rb, line 70
def self.raw_must
  output = raw while output == nil
  return output
end