-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd_incomplete.rb
executable file
·114 lines (97 loc) · 1.41 KB
/
lcd_incomplete.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env ruby
class Display
def initialize(integer, scale, lcds)
@integer = integer
@scale = scale
@lcds = lcds
end
def showargs
puts " The integer is #{@integer} with a scale of #{@scale} ".center(60,'*')
end
# Display the LCD integer
def display
digits = @integer.chars.map { |n| @lcds[n.to_i] }
digits.each do |digit|
digit.each do |row|
# Scale horizontally
row[1, 1] = row[1, 1] * @scale
end
digit.each do |row|
# Scale vertically
if row =~ /\|/
@scale.times { puts row }
else
puts row
end
end
end
end
end
# Fetching the arguments
if ARGV.size == 2
num = ARGV[0]
scale = ARGV[1].to_i
elsif ARGV.size == 1
scale = 1
num = ARGV[0]
# Printing message to explain the program if no arguments
else
puts " This program accepts 1 or 2 arguments ".center(60,'*')
puts " lcd <integer to scale> [ <scale> DEFAULT=1 ]"
exit
end
template = [
[' - ',
'| |',
' ',
'| |',
' - '],
[' ',
' |',
' ',
' |',
' '],
[' - ',
' |',
' - ',
'| ',
' - '],
[' - ',
'| ',
' - ',
'| ',
' - '],
[' ',
'| |',
' - ',
' |',
' '],
[' - ',
'| ',
' - ',
' |',
' - '],
[' - ',
'| ',
' - ',
'| |',
' - '],
[' - ',
' |',
' ',
' |',
' '],
[' - ',
'| |',
' - ',
'| |',
' - '],
[' - ',
'| |',
' - ',
' |',
' - ']
]
lcd = Display.new(num, scale, template)
lcd.display
lcd.showargs