Module: ColorPuts
- Defined in:
- lib/color_puts.rb,
lib/color_puts/version.rb
Defined Under Namespace
Classes: NullDecorator
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.colorize(string, decorator: DECORATOR) ⇒ Object
Example:
colorize("There was a (green)[field] and (blue)[sky].")
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/color_puts.rb', line 23 def self.colorize(string, decorator: DECORATOR) Sai::Registry.send(:lookup).keys Sai::ANSI::STYLES.keys string .dup .gsub(REGEXP) do |markdown| color, text = markdown.scan(REGEXP)[0] if color.start_with?("#") then decorator.hex(color) elsif color == "rainbow" then decorator.rainbow(RAINBOW) elsif Sai::ANSI::STYLES.key?(color.to_sym) then decorator.public_send(color) elsif Sai::Registry.send(:lookup).key?(color.sub(/\Aon_/, "").to_sym) then decorator.public_send(color) else NullDecorator end .decorate(text) .to_s end end |