-
-
Save jeroenvandijk/259581 to your computer and use it in GitHub Desktop.
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 | |
module Chars | |
extend self | |
def scale(args, options={}) | |
scale = options[:scale] | |
chars = args.map { |x| char(x.to_i).map { |row| row.split("") } } | |
print_chars scale_vertically(scale_horizontally(chars, scale), scale) | |
end | |
# private | |
def chars | |
@chars ||= [ | |
[ | |
" |", | |
" |", | |
" |", | |
" |", | |
" |" | |
], | |
[ | |
" - ", | |
" |", | |
" - ", | |
"| ", | |
" _ " | |
], | |
[ | |
" - ", | |
" |", | |
" - ", | |
" |", | |
" _ " | |
] | |
] | |
end | |
def char(i) | |
self.chars[i - 1] | |
end | |
def scale_horizontally(chars, scale) | |
chars.map do |row| | |
row.map do |cell| | |
[0, [1] * scale, 2].flatten.map { |i| cell[i] } | |
end | |
end | |
end | |
def scale_vertically(chars, scale) | |
chars.map do |row| | |
[0, [1] * scale, 2, [3] * scale, 4].flatten.map { |i| row[i] } | |
end | |
end | |
def print_chars(chars) | |
puts chars.map { |row| row.map{ |col| col.join } }.join("\n") | |
end | |
end | |
unless @loaded | |
@loaded = true | |
require 'rubygems' | |
require 'boson' | |
# Default scale is 10 | |
parser = Boson::OptionParser.new(:scale=>10) | |
options = parser.parse(ARGV) | |
Chars.scale(parser.non_opts, options) | |
end | |
# Examples | |
# | |
# ./chars.rb 1 2 3 | |
# ./chars.rb 1 2 -s=5 | |
# ./chars.rb 1 2 3 --scale=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment