Last active
July 30, 2016 17:08
-
-
Save a17levine/cd90d88223ff33cc5566 to your computer and use it in GitHub Desktop.
Pixel Sorter Says
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'nokogiri' | |
def generate_pixel_sorter_saying | |
random_page_number_between_one_and_forty = rand(1 .. 40) | |
# load the quote_page | |
quote_page = Nokogiri::HTML(open("http://www.brainyquote.com/quotes/topics/topic_art#{random_page_number_between_one_and_forty}.html")) | |
# get all the quotes on said quote_page | |
all_quote_elements_on_quote_page = quote_page.css(".bqQuoteLink a").map{|e| e.text} | |
# choose a random quote | |
chosen_quote = all_quote_elements_on_quote_page.sample | |
# clean up quote from punctuation and uppercasing | |
chosen_quote = chosen_quote.downcase.gsub(/[^a-z0-9\s]/i, '') | |
# get last three words of quote | |
chosen_quote = chosen_quote.split(" ")[-3..-1].join(" ") | |
return chosen_quote | |
end | |
10.times {p generate_pixel_sorter_saying} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cglinka