Created
June 7, 2014 19:12
-
-
Save michaelfeathers/f52c48e2455a75374dc8 to your computer and use it in GitHub Desktop.
Audiobook scripting utility
This file contains hidden or 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
# Accepts program file names on the command line and renders them to stdout as a sequence of spoken words | |
token_map = { | |
"[" => "left-square-bracket", | |
"]" => "right-square-bracket", | |
"!" => "exclamation-point", | |
"\\" => "backslash", | |
"#" => "pound sign", | |
"\"" => "double-quote", | |
"$" => "dollar-sign", | |
"%" => "percent-sign", | |
"&" => "ampersand", | |
"'" => "single-quote", | |
"(" => "left-paren", | |
")" => "right-paren", | |
"*" => "star", | |
"+" => "plus-sign", | |
"," => "comma", | |
"." => "dot", | |
"/" => "forward-slash", | |
":" => "colon", | |
";" => "semicolon", | |
"<" => "less-than sign", | |
"=" => "equals sign", | |
">" => "greater-than sign", | |
"?" => "question mark", | |
"@" => "at sign", | |
"^" => "caret", | |
"_" => "underscore", | |
"`" => "back tic", | |
"{" => "left curly-brace", | |
"|" => "vertical bar", | |
"}" => "right curly-brace", | |
"~" => "tilde", | |
"-" => "dash", | |
" " => "space", | |
"\n" => "new line", | |
"\t" => "tab", | |
} | |
puts ARGF.read | |
.chars | |
.chunk {|ch| ch =~ /[[:alnum:]]/ ? :alone : true } | |
.map {|key,values| key == :alone ? values.join : values } | |
.flatten(1) | |
.zip((0...Float::INFINITY)) | |
.map {|token,line_no| "#{line_no}: #{token_map[token] || token}" } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment