/thesortinghat

Reads records about people and displays list of people sorted by attribute

Primary LanguageClojureEclipse Public License 1.0EPL-1.0

The Sorting Hat

Reads records containing facts about people. Displays lists of people sorted by their attributes.

Enchanted hat that once belonged to Godric Gryffindor and sorts students into Hogwarts houses

Image of The Sorting Hat

Usage

The Sorting Hat is written in Clojure and requires Leiningen to be installed.

Command Line interface

To read a file using the command line interface:

lein run <input-file>

Example input files are provided in resources:

lein run resources/people.csv

Input files are expected to consist of only records separated by lines with field separated by commas, pipes, or spaces. Fields may be quoted if they contain a separator.

Output is printed to stdout; the records are printed in 3 different sort orders.

REST API

Start the server:

lein ring server

This will open a browser tab pointing at http://localhost:3000

You can use the interface to test the functionality interactively.

Alternatively, to submit records via curl:

curl -X POST \
     -H 'Content-Type: application/text' \
     -d 'Potter, Harry, male, green, 1/1/1985' \
     localhost:3000/records
curl -X POST \
     -H 'Content-Type: application/text' \
     -d 'Granger | Hermione | female | red | 3/1/1985' \
     localhost:3000/records
curl -X POST \
     -H 'Content-Type: application/text' \
     -d 'Weasley Ginny female orange 4/4/1986' \
     localhost:3000/records

To retrieve records:

  1. curl http://localhost:3000/records/gender Female first, then last name ascending
  2. curl http://localhost:3000/records/birthdate Birth date oldest to youngest
  3. curl http://localhost:3000/records/name Last name descending

Developing

To run the tests:

lein test or lein test-refresh

To check code coverage:

lein cloverage

License

Copyright © 2017 Timothy Pratley

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.