Module: ConsoleStyle::Functions
Constant Summary collapse
- GREEN =
TODO: handle emoji compatibility
32
- RED =
31
- CYAN =
36
- GOOD =
"\t✅".freeze
- BAD =
"\t⭕".freeze
- NO =
"\t❌".freeze
Instance Method Summary collapse
-
#execute(command) ⇒ Object
Execute commands.
- #execute_split_lines(command) ⇒ Object
- #execute_with_new_line(command) ⇒ Object
- #print_heading(text) ⇒ Object
-
#snakecase(str) ⇒ Object
From: github.com/savonrb/nori.
- #space(size) ⇒ Object
-
#style(str, style_code) ⇒ Object
Printing commands.
Instance Method Details
#execute(command) ⇒ Object
Execute commands
54 55 56 |
# File 'lib/console-style/functions.rb', line 54 def execute(command) `#{command}`.gsub(" \n", '').gsub("\n", '') end |
#execute_split_lines(command) ⇒ Object
62 63 64 |
# File 'lib/console-style/functions.rb', line 62 def execute_split_lines(command) `#{command}`.split("\n") end |
#execute_with_new_line(command) ⇒ Object
58 59 60 |
# File 'lib/console-style/functions.rb', line 58 def execute_with_new_line(command) `#{command}` end |
#print_heading(text) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/console-style/functions.rb', line 23 def print_heading(text) line = '################################' puts line buffer = (line.size / 2) - (text.size / 2) - 2 buffer = 1 if buffer < 1 output = "#{space(buffer)}#{text}#{space(buffer)}" output += ' ' if output.size < line.size puts "##{output}#" puts line end |
#snakecase(str) ⇒ Object
From: github.com/savonrb/nori
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/console-style/functions.rb', line 39 def snakecase(str) str = str.dup str.gsub!(/::/, '/') str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') str.gsub!(' ', '_') str.tr!('.', '_') str.tr!('-', '_') str.downcase! str end |
#space(size) ⇒ Object
19 20 21 |
# File 'lib/console-style/functions.rb', line 19 def space(size) (1..size).map { |_| " " }.join("") end |
#style(str, style_code) ⇒ Object
Printing commands
15 16 17 |
# File 'lib/console-style/functions.rb', line 15 def style(str, style_code) "\e[#{style_code}m#{str}\e[0m" end |