Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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("{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
10.times {p generate_pixel_sorter_saying}

This comment has been minimized.

Copy link
Owner Author

@a17levine a17levine commented Jul 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.