Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created December 13, 2010 22:34
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 jcromartie/c9522a2f56722f2a0d8e to your computer and use it in GitHub Desktop.
Save jcromartie/c9522a2f56722f2a0d8e to your computer and use it in GitHub Desktop.
;; rules are functions that figure out how to mask values based on a table and column
;; a rule should be like (fn [table col] return-value-transform-fn)
(defn rule
"Builds compound rule out of rules, testing each"
[& rules]
(fn [table col]
(some #(% (.toLowerCase table) (.toLowerCase col))
rules)))
(defn table
[table-re & rules]
(fn [table col]
(when (re-find table-re table)
((apply rule rules) table col))))
(defn col
[col-re f]
(table-col #".*" col-re f))
(defmacro defrule
"Shorthand to define compound rules"
[name & rules]
`(def ~name (rule ~@rules)))
(defmacro normalized
"Thread a value through normalize and other fns"
[& fns]
`(fn [x#] (-> x# normalize ~@fns)))
(defrule default-rule
(col #"(email|id$|no$|number|account|acct|phone|fax)" (normalized randomize-alphanum))
(col #"(addr|street)" (normalized replace-street-address))
(col #"(vendor|payee|company)" (normalized replace-company-name))
(col #"(first|mid).*name" (normalized replace-given-name))
(col #"last.*name" (normalized replace-surname))
(col #"(login|userid)" (normalized randomize-alphanum))
(col #"(note|comment|notes)" replace-words))
(defrule datahub-rule
(table #"tblemployeesclients"
(col #"clientid" (normalized randomize-alphanum)))
(table #"tblclients"
(col #"lastname" (normalized replace-company-name)))
(col #"clientssn" (normalized randomize-alphanum))
default-rule)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment