├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.markdown ├── LICENSE.txt ├── Makefile ├── README.markdown ├── VERSION ├── shard.yml ├── spec └── phonetic_alphabetizer_spec.cr └── src ├── phonetic_alphabetizer.cr └── spellout.cr /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /doc/ 3 | /tmp/ 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: crystal 2 | sudo: false 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.markdown: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This code of conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at sferik@gmail.com. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 45 | version 1.3.0, available at 46 | [http://contributor-covenant.org/version/1/3/0/][version] 47 | 48 | [homepage]: http://contributor-covenant.org 49 | [version]: http://contributor-covenant.org/version/1/3/0/ 50 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Erik Michaels-Ober 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=spellout 2 | VERSION=`cat VERSION` 3 | BIN_DIR=bin 4 | SRC_DIR=src 5 | TMP_DIR=tmp 6 | BIN_FILE=$(BIN_DIR)/$(NAME) 7 | SRC_FILE=$(SRC_DIR)/$(NAME).cr 8 | 9 | test: 10 | crystal spec 11 | 12 | $(SRC_FILE): $(SRC_DIR)/phonetic_alphabetizer.cr 13 | 14 | $(BIN_FILE): $(SRC_FILE) 15 | mkdir -p $(BIN_DIR) 16 | crystal build $(SRC_FILE) -o $(BIN_FILE) --release 17 | 18 | release: $(BIN_FILE) test 19 | git diff --exit-code && \ 20 | git diff-index --quiet --cached HEAD && \ 21 | git tag v$(VERSION) && \ 22 | git push && \ 23 | git push --tags 24 | 25 | clean: 26 | rm -rf $(BIN_DIR) 27 | rm -rf $(TMP_DIR) 28 | 29 | .PHONY: clean test release 30 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Spellout 2 | ======== 3 | 4 | [![Build Status](https://travis-ci.org/sferik/spellout.svg?branch=master)](https://travis-ci.org/sferik/spellout) 5 | 6 | Spellout is a command-line tool that converts input into the [International 7 | Radiotelephony Spelling Alphabet][nato]. 8 | 9 | [nato]: https://en.wikipedia.org/wiki/NATO_phonetic_alphabet 10 | 11 | It accepts input via command-line arguments or standard input. 12 | 13 | #### Examples 14 | 15 | $ spellout cable9 16 | Charlie Alpha Bravo Lima Echo Niner 17 | 18 | $ echo cable9 > /path/to/file 19 | $ spellout < /path/to/file 20 | Charlie Alpha Bravo Lima Echo Niner 21 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.0.0 2 | -------------------------------------------------------------------------------- /shard.yml: -------------------------------------------------------------------------------- 1 | name: spellout 2 | version: 1.0.0 3 | 4 | authors: 5 | - Erik Michaels-Ober 6 | 7 | license: MIT 8 | -------------------------------------------------------------------------------- /spec/phonetic_alphabetizer_spec.cr: -------------------------------------------------------------------------------- 1 | require "spec" 2 | require "../src/phonetic_alphabetizer" 3 | 4 | describe PhoneticAlphabetizer do 5 | it "converts uppercase strings to the phonetic alphabet" do 6 | object = PhoneticAlphabetizer.new("WTF") 7 | object.call.should eq("Whiskey Tango Foxtrot") 8 | end 9 | 10 | it "converts lowercase strings to the phonetic alphabet" do 11 | object = PhoneticAlphabetizer.new("wtf") 12 | object.call.should eq("Whiskey Tango Foxtrot") 13 | end 14 | 15 | it "converts strings with spaces to the phonetic alphabet" do 16 | object = PhoneticAlphabetizer.new("foo bar") 17 | object.call.should eq("Foxtrot Oscar Oscar Space Bravo Alpha Romeo") 18 | end 19 | 20 | it "converts string with stops to the phonetic alphabet" do 21 | object = PhoneticAlphabetizer.new("foo.bar") 22 | object.call.should eq("Foxtrot Oscar Oscar Stop Bravo Alpha Romeo") 23 | end 24 | 25 | it "converts strings with dashes to the phonetic alphabet" do 26 | object = PhoneticAlphabetizer.new("foo-bar") 27 | object.call.should eq("Foxtrot Oscar Oscar Dash Bravo Alpha Romeo") 28 | end 29 | 30 | it "converts the string to the phonetic alphabet" do 31 | object = PhoneticAlphabetizer.new("123") 32 | object.call.should eq("One Two Three") 33 | end 34 | 35 | it "passes through non-dictionary characters" do 36 | object = PhoneticAlphabetizer.new("foo_bar") 37 | object.call.should eq("Foxtrot Oscar Oscar _ Bravo Alpha Romeo") 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /src/phonetic_alphabetizer.cr: -------------------------------------------------------------------------------- 1 | class PhoneticAlphabetizer 2 | DICTIONARY = { 3 | ' ' => "Space", 4 | '-' => "Dash", 5 | '.' => "Stop", 6 | '0' => "Zero", 7 | '1' => "One", 8 | '2' => "Two", 9 | '3' => "Three", 10 | '4' => "Four", 11 | '5' => "Five", 12 | '6' => "Six", 13 | '7' => "Seven", 14 | '8' => "Eight", 15 | '9' => "Niner", 16 | 'A' => "Alpha", 17 | 'B' => "Bravo", 18 | 'C' => "Charlie", 19 | 'D' => "Delta", 20 | 'E' => "Echo", 21 | 'F' => "Foxtrot", 22 | 'G' => "Golf", 23 | 'H' => "Hotel", 24 | 'I' => "India", 25 | 'J' => "Juliet", 26 | 'K' => "Kilo", 27 | 'L' => "Lima", 28 | 'M' => "Mike", 29 | 'N' => "November", 30 | 'O' => "Oscar", 31 | 'P' => "Papa", 32 | 'Q' => "Quebec", 33 | 'R' => "Romeo", 34 | 'S' => "Sierra", 35 | 'T' => "Tango", 36 | 'U' => "Uniform", 37 | 'V' => "Victor", 38 | 'W' => "Whiskey", 39 | 'X' => "X-ray", 40 | 'Y' => "Yankee", 41 | 'Z' => "Zulu", 42 | } 43 | 44 | def initialize(text : String) 45 | @text = text 46 | end 47 | 48 | def call 49 | @text.chars.map { |char| DICTIONARY.fetch(char.upcase, char) }.join(' ') 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /src/spellout.cr: -------------------------------------------------------------------------------- 1 | require "./phonetic_alphabetizer" 2 | 3 | if !ARGV.empty? 4 | ARGV.each do |arg| 5 | puts PhoneticAlphabetizer.new(arg).call 6 | end 7 | elsif !STDIN.tty? && !STDIN.closed? 8 | puts PhoneticAlphabetizer.new(STDIN.gets_to_end).call 9 | else 10 | abort("Usage: spellout [arguments]") 11 | end 12 | --------------------------------------------------------------------------------