Last active
December 15, 2015 10:29
-
-
Save octosteve/5245726 to your computer and use it in GitHub Desktop.
Fetch by category from Rubeque. You need the rest-client gem
This file contains 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
#!/usr/bin/env ruby | |
require 'rest-client' | |
require 'json' | |
class Rubeque | |
def initialize | |
@questions = categorize | |
end | |
def categories | |
puts @questions.keys | |
end | |
def questions_for(category) | |
@questions[category].sort_by {|q| q["difficulty"].to_i}.each do |question| | |
puts "Difficulty #{question["difficulty"]}" | |
puts question["instructions"] | |
puts question["code"] | |
puts "-" * 40 | |
puts | |
end | |
end | |
private | |
def categorize | |
result = JSON.load(RestClient.get("http://www.rubeque.com/problems.json")) | |
questions = Hash.new {|k,v| k[v] = [] } | |
result.each_with_object(questions) do |r| | |
if r["tags"] | |
r["tags"].each do |t| | |
questions[t["name"].strip] << r | |
end | |
else | |
questions["untagged"] << r | |
end | |
end | |
end | |
end | |
rbq = Rubeque.new | |
rbq.questions_for 'enumerables' | |
rbq.categories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment