Skip to content

Instantly share code, notes, and snippets.

@EricLondon
Created March 19, 2012 20:28
Show Gist options
  • Save EricLondon/2126811 to your computer and use it in GitHub Desktop.
Save EricLondon/2126811 to your computer and use it in GitHub Desktop.
Random Tree Token Generator
# Usage:
# tree = RandomTreeToken.new
# puts tree.generate
class RandomTreeToken
def initialize
require 'net/http'
url = 'http://treesofnorthamerica.net/'
body = Net::HTTP.get_response(URI.parse(url)).body
@trees = []
body.scan(/<a.*?href.*?>(.*?)<\/a>/im) do |tree|
@trees << tree[0].gsub(/[^0-9a-z]/i, '')
end
@tree_count = @trees.size
end
def generate
@trees[rand(@tree_count)] + rand(100).to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment