Module: RandomYouTube

Defined in:
lib/randomyoutube.rb,
lib/randomyoutube/version.rb

Constant Summary collapse

ACC_CHARS =
(('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ["\n"]).flatten.join
REQUESTOR =
"https://gdata.youtube.com/feeds/api/videos?q="
THREE_WORDS =
"shuf -n 3 /usr/share/dict/words"
VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#mywordsObject (readonly)

Returns the value of attribute mywords.



16
17
18
# File 'lib/randomyoutube.rb', line 16

def mywords
  @mywords
end

Class Method Details

.humanObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/randomyoutube.rb', line 25

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_mustObject



54
55
56
57
# File 'lib/randomyoutube.rb', line 54

def self.human_must
  output = pretty while output == nil
  puts output
end

.local_execObject



18
19
20
21
22
23
# File 'lib/randomyoutube.rb', line 18

def self.local_exec
  @mywords = `#{THREE_WORDS}`
  @mywords = @mywords.strip_byac(ACC_CHARS).split("\n")
  urlsearch = REQUESTOR + @mywords.join('+')
  Nokogiri::XML(open(urlsearch))
end

.prettyObject



36
37
38
39
40
41
42
43
# File 'lib/randomyoutube.rb', line 36

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_mustObject



59
60
61
62
# File 'lib/randomyoutube.rb', line 59

def self.pretty_must
  output = pretty while output == nil
  return output
end

.rawObject



45
46
47
48
49
50
51
52
# File 'lib/randomyoutube.rb', line 45

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_mustObject



64
65
66
67
# File 'lib/randomyoutube.rb', line 64

def self.raw_must
  output = raw while output == nil
  return output
end