Module: Colorate
- Defined in:
- lib/colorate.rb,
lib/colorate/version.rb,
lib/colorate/constants.rb
Constant Summary collapse
- VERSION =
'1.0.2'
- COLORS =
{ black: "\e[0;30m", blue: "\e[0;34m", green: "\e[0;32m", cyan: "\e[0;36m", red: "\e[0;31m", purple: "\e[0;35m", brown: "\e[0;33m", light_gray: "\e[0;37m", dark_gray: "\e[1;30m", light_blue: "\e[1;34m", light_green: "\e[1;32m", light_cyan: "\e[1;36m", light_red: "\e[1;31m", light_purple: "\e[1;35m", yellow: "\e[1;33m", white: "\e[1;37m" }
- BOLD_BEGIN =
"\033[1m"
- UNDERLINE_BEGIN =
"\033[4m"
- DECORATION_END =
"\033[0m"
- OVERALL_END =
"\e[0m"
Class Method Summary collapse
Class Method Details
.defaults ⇒ Object
18 19 20 |
# File 'lib/colorate.rb', line 18 def self.defaults { bold: false, underline: false } end |
.method_missing(method, *args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/colorate.rb', line 5 def self.method_missing(method, *args, &block) raise ArgumentError, 'Color not supported' unless COLORS.keys.include?(method) output_string = args[0] = args[1] || {} = defaults.merge() output_string = BOLD_BEGIN + output_string + DECORATION_END if [:bold] output_string = UNDERLINE_BEGIN + output_string + DECORATION_END if [:underline] COLORS[method.to_sym] + output_string + OVERALL_END end |