            (replace \. \/))))
 
 (defn- title->fn [title]
-  (.toLowerCase (cs/replace title #"[^\w]" "-")))
+  (.toLowerCase (cs/replace title #"\W" "-")))
 
 (defn- drop-replace-me [fn]
   (let [t (slurp fn)


(def fore-url "http://4clojure.com/api/problem/")

;; TODO - Create projects from a problem (maybe use the spawn plugin?).
(defn fore-prob [project prob-num]
  (try
    ;; TODO - Check HTTP status.
    (let [json (json/parse-string
                 (:body (http/get (str fore-url prob-num))))
          title (json :title)]
      (if-not (write-tests project json) ; spit returns nil by default hence
                                         ; the inversion of logic.
        (println (str "Problem \"" title "\" added!"))
        (println (str "Problem \"" title "\" has already been added!"))))
    (catch Exception e
      (println (str "Failed setting problem " prob-num ": " (.getMessage e)))
      (shutdown-agents))))

(ns leiningen.fore-prob
  "Populate the current project with a 4clojure problem."
  (:require [clj-http.client :as http]
            [clojure.java.io :as io])
  (:use [clojure.string :as cs :exclude [replace reverse]]))

