Skip to content

Instantly share code, notes, and snippets.

@a17levine
Last active July 30, 2016 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a17levine/cd90d88223ff33cc5566 to your computer and use it in GitHub Desktop.
Save a17levine/cd90d88223ff33cc5566 to your computer and use it in GitHub Desktop.
Pixel Sorter Says
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}
@a17levine
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment