Sha256: b145a6790e8a0e6a4639723e601dba42324212f9e7335f1ac84c0e329c4ce38b

Contents?: true

Size: 855 Bytes

Versions: 3

Compression:

Stored size: 855 Bytes

Contents

require 'open-uri'
require 'nokogiri'

module UrbanPass
  class Generate

    def generate
      # Generate word:
      urban = random_word

      # Remove the extra spaces
      word = remove_spaces(urban)

      # Return the length of the phrase and print out the word
      puts "Your word is: #{word}"
      puts "The word is #{phrase_length(word)} charcters long"
    end

    def random_word
      page = Nokogiri::HTML(open("http://urbandictionary.com/random.php"))
      word = page.css('a.word')[0].text
    end

    def remove_spaces(phrase)
      phrase.gsub(" ", "")
    end


    def phrase_length(phrase)
      return phrase.length
    end

    def generate_phrase
      arr = []
      4.times do
        word = random_word
        arr << remove_spaces(word)
      end
      pass_phrase = arr.join
      return pass_phrase
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
urban_pass-0.0.2.2 lib/urban_pass/generate.rb
urban_pass-0.0.2.1 lib/urban_pass/generate.rb
urban_pass-0.0.2 lib/urban_pass/generate.rb