class UrbanPass::Generate
Public Instance Methods
copy(phrase)
click to toggle source
# File lib/urban_pass/generate.rb, line 47 def copy(phrase) word = Clipboard.copy(phrase) if Clipboard.paste == phrase return word end end
defination(word)
click to toggle source
# File lib/urban_pass/generate.rb, line 54 def defination(word) dictionary = Urban::Dictionary.new return dictionary.search(word) end
generate_phrase()
click to toggle source
# File lib/urban_pass/generate.rb, line 18 def generate_phrase threads = [] 4.times do threads << Thread.new { Thread.current["word"] = random_word } end phrase = [] # two arrays > string concatenation threads.each {|t| t.join; phrase << t["word"]} phrase = phrase.join("-") pass_phrase = remove_spaces(phrase) copy(pass_phrase) return pass_phrase end
generate_word()
click to toggle source
# File lib/urban_pass/generate.rb, line 10 def generate_word # Generate word: urban = random_word # Remove the extra spaces remove_spaces(urban) end
phrase_length(phrase)
click to toggle source
# File lib/urban_pass/generate.rb, line 43 def phrase_length(phrase) return phrase.length end
random_word()
click to toggle source
# File lib/urban_pass/generate.rb, line 31 def random_word page = Nokogiri::HTML(open("http://urbandictionary.com/random.php")) page.css('a.word')[0].text rescue SocketError puts "Your not connected to the internet, silly!" exit end
remove_spaces(phrase)
click to toggle source
# File lib/urban_pass/generate.rb, line 39 def remove_spaces(phrase) phrase.gsub(" ", "") end