Last active
August 29, 2015 14:12
-
-
Save D4v1X/15b27360432a16898fac to your computer and use it in GitHub Desktop.
LCD Numbers, Ruby Quiz.
This file contains 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
#File : lcd.rb | |
#Author David Santiago Barrera | |
#Size = 1 | |
# - - - - - - - - | |
#| | | | | | | | | | | | | | | |
# - - - - - - - | |
#| | | | | | | | | | | | | | |
# - - - - - - | |
#Analisis number 0 with size 1 | |
#CODED_NUMBER=" - | | | | - " [width = 4] | |
#Simplifying-> | |
#CODED_NUMBER= yh vd nh vd yh | |
#Size = 2 | |
# -- -- -- -- -- -- -- -- | |
#| | | | | | | | | | | | | | | |
#| | | | | | | | | | | | | | | |
# -- -- -- -- -- -- -- | |
#| | | | | | | | | | | | | | |
#| | | | | | | | | | | | | | |
# -- -- -- -- -- -- -- | |
#Analisis number 0 with size 2 | |
#CODED_NUMBER=" -- | || | | || | -- " [width = 5] | |
#Simplifying-> | |
#CODED_NUMBER= yh vd vd nh vd vd H | |
#CODED_NUMBER= yh vd*size nh vd*size H | |
#yh = Yes Horizontal | |
#nh = No Horizontal | |
#vd = Vertical Double | |
#vr = Vertical Rigth | |
#vl = Vertical Left | |
class LCD | |
SEPARATOR = ' ' | |
VERTICAL = 2 | |
HORIZONTAL = 3 | |
def initialize(number, size = 2) | |
@size = size.to_i | |
@number = number | |
@codes ={ | |
yh: ' ' + '-' * @size + ' ', # ' - ' | |
nh: ' ' + ' ' * @size + ' ', # ' ' | |
vd: ['|' + ' ' * @size + '|'] * @size , # '| |' | |
vr: [' ' + ' ' * @size + '|'] * @size , # ' |' | |
vl: ['|' + ' ' * @size + ' '] * @size , # '| ' | |
} | |
@coded_numbers = [ | |
[@codes[:yh], @codes[:vd], @codes[:nh], @codes[:vd], @codes[:yh]], #number 0 | |
[@codes[:nh], @codes[:vr], @codes[:nh], @codes[:vr], @codes[:nh]], #number 1 | |
[@codes[:yh], @codes[:vr], @codes[:yh], @codes[:vl], @codes[:yh]], #number 2 | |
[@codes[:yh], @codes[:vr], @codes[:yh], @codes[:vr], @codes[:yh]], #number 3 | |
[@codes[:nh], @codes[:vd], @codes[:yh], @codes[:vr], @codes[:nh]], #number 4 | |
[@codes[:yh], @codes[:vl], @codes[:yh], @codes[:vr], @codes[:yh]], #number 5 | |
[@codes[:yh], @codes[:vl], @codes[:yh], @codes[:vd], @codes[:yh]], #number 6 | |
[@codes[:yh], @codes[:vr], @codes[:nh], @codes[:vr], @codes[:nh]], #number 7 | |
[@codes[:yh], @codes[:vd], @codes[:yh], @codes[:vd], @codes[:yh]], #number 8 | |
[@codes[:yh], @codes[:vd], @codes[:yh], @codes[:vr], @codes[:yh]], #number 9 | |
] | |
end | |
def print | |
(0...(VERTICAL * @size + HORIZONTAL)).each do |i| | |
puts @number.chars.collect { |number| @coded_numbers[number.to_i].flatten[i] }.join SEPARATOR | |
end | |
end | |
end | |
if ARGV.include?('-s') && ARGV[2] =~ /\A[0-9]+\z/ && ARGV[1] =~ /\A[0-9]+\z/ && ARGV.size == 3 | |
lcd = LCD.new(ARGV[2],ARGV[1]) | |
lcd.print | |
elsif ARGV[0] =~ /\A[0-9]+\z/ && ARGV.size == 1 | |
lcd = LCD.new(ARGV[0]) | |
lcd.print | |
else | |
puts "Usage: #$0 [-s Size] Number" | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well done!! 👍