Created
November 30, 2011 05:18
-
-
Save boscomonkey/1408137 to your computer and use it in GitHub Desktop.
Ruby Quiz #14 - an evolving solution for SF Ruby Hack night
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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
Numbers = [ | |
[" - ", | |
"| |", | |
"| |", | |
"| |", | |
" - "], | |
[" | ", | |
" | ", | |
" | ", | |
" | ", | |
" | "], | |
["-- ", | |
" |", | |
" - ", | |
"| ", | |
" --"], | |
["-- ", | |
" |", | |
"-- ", | |
" |", | |
"-- "], | |
["| |", | |
"| |", | |
" - ", | |
" |", | |
" |"], | |
[" --", | |
"| ", | |
" - ", | |
" |", | |
"-- "], | |
[" --", | |
"| ", | |
" - ", | |
"| |", | |
" - "], | |
["-- ", | |
" |", | |
" |", | |
" |", | |
" |"], | |
[" - ", | |
"| |", | |
" - ", | |
"| |", | |
" - "], | |
[" - ", | |
"| |", | |
" - ", | |
" |", | |
"-- "] | |
] | |
def process msg # define function "process" w/ argument "msg" | |
scale = 1 | |
(0..4).each {|layer_index| # step through layers 0 to 4 | |
msg.each_char {|char| # for each character in argument | |
digit = char.to_i # convert char to integer | |
cell = Numbers[digit] # find the correct cell | |
layer = cell[layer_index] # peel off the ith layer of the cell | |
(0..scale).each {print layer} | |
# space needed to separate characters horizontally | |
print " " | |
} # end loop each char | |
# output a newline to wrap pointer to beginning of line | |
print "\n" | |
} # end loop each layer | |
end | |
process ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment