-
Notifications
You must be signed in to change notification settings - Fork 9
/
ruby_letters.rb
111 lines (104 loc) · 2.99 KB
/
ruby_letters.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
# Ruby Letters
# Author: Derek Nguyen
# GitHub: https://github.com/dereknguyen269
require './block_letters'
require './letters'
require 'colorized_string'
require 'dotenv/load'
require 'rainbow_printer'
class RubyLetters
def initialize(input_string)
@input_string = input_string
@letters = Letters.new.all
@colors = []
end
def render
length = @input_string.size
@colorized = ColorizedString.colors
@colorized.shift
y = 0
if ENV['export']
# Clear file content before write
file_path = ENV['file_path'] ? ENV['file_path'] : 'tmp/output.txt'
File.open(file_path, 'w') {|file| file.truncate(0) }
end
while y <= 5 do
text = ''
(0...length).each do |x|
text += "#{@letters[get_key(x)].contents[y]}"
end
if ENV['export']
# Write text to file txt
File.write(file_path, "#{text}\n", mode: 'a')
elsif ENV['color'].to_s.empty?
text_color = unique_color
bg_color = :black
content = ColorizedString[text].colorize(:color => text_color.to_sym, :background => bg_color.to_sym)
STDERR.puts content
else
if ENV['color'] == 'rainbow'
rb_puts text
else
customize_color = ENV['color'].split(',')
text_color = customize_color[0] || :white
bg_color = customize_color[1] || :black
STDERR.puts ColorizedString[text].colorize(:color => text_color.to_sym, :background => bg_color.to_sym)
end
end
y += 1
end
end
private
def get_key(character)
case @input_string[character]
when " " then key = :space
when "!" then key = :exclamation
when "." then key = :period
when "-" then key = :hyphen
when "+" then key = :plus
when "=" then key = :equal
when "_" then key = :underscore
when "@" then key = :at
when "#" then key = :hash
when "?" then key = :question
when "$" then key = :dollar
when "%" then key = :percent
when "*" then key = :star
when "^" then key = :caret
when ">" then key = :chevron_right
when "<" then key = :chevron_left
when "%" then key = :percent
when "(" then key = :open_parenthesis
when ")" then key = :closed_parenthesis
when "{" then key = :opening_curly_braces
when "}" then key = :closed_curly_braces
when "[" then key = :opening_braces
when "]" then key = :closed_braces
when "¬" then key = :not_sign
when "Ñ" then key = :ñ
when "/" then key = :slash
when "\\" then key = :backslash
when "|" then key = :pipe
when "¡" then key = :exclamation_inv
when ":" then key = :colon
when ";" then key = :semicolon
else key = @input_string[character].downcase.to_sym
end
key
end
def unique_color
color = @colorized.sample
if @colors.include?(color)
unique_color
else
@colors << color
color
end
end
end
if ARGV.count.zero?
str = "Ruby Letters"
RubyLetters.new(str).render
else
ARGV.each {|input| RubyLetters.new(input).render }
end