First, you'll need to install Homebrew. Instructions here: https://brew.sh
Paste the content above into a file at /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/mapmap.rb.
Then you can just run brew install mapmap and the rest is automatic.
If it works for you, then you can submit it to the homebrew-core project. After the Homebrew team accepts the formula code, then everyone with Homebrew can install the package with the brew install command.