Last active
June 18, 2016 01:23
-
-
Save cemerick/fd824dea77c9736225531a5cc97affee to your computer and use it in GitHub Desktop.
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
(def percentage-spec (s/conformer #(or (some-> (re-matches #"(-?\d+(\.\d+)?)%" %) (nth 1) Double/parseDouble) | |
::s/invalid) | |
#(str % "%"))) | |
(s/def ::absolute-coordinate number?) | |
(s/def ::pct-coordinate percentage-spec) | |
(s/def ::coordinate (s/or :abs ::absolute-coordinate | |
:pct ::pct-coordinate)) | |
(def specrec (s/cat :lx ::coordinate | |
:by ::coordinate | |
:rx ::coordinate | |
:ty ::coordinate)) | |
pdfdata.ops> (s/conform ::coordinate 123) | |
[:abs 123] | |
pdfdata.ops> (s/unform ::coordinate *1) | |
123 | |
pdfdata.ops> (s/conform ::coordinate "-50.2%") | |
[:pct -50.2] | |
pdfdata.ops> (s/unform ::coordinate *1) | |
-50.2% | |
pdfdata.ops> (s/conform specrec [12 "-50.2%" -99.1 "2%"]) | |
{:lx [:abs 12], :by [:pct -50.2], :rx [:abs -99.1], :ty [:pct 2.0]} | |
pdfdata.ops> (s/unform specrec *1) | |
(12 "-50.2%" -99.1 "2%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment