Module: Unicolor
- Defined in:
- lib/unicolor.rb,
lib/unicolor/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
- .color_for(str) ⇒ Object
- .colorize(str) ⇒ Object
- .colors ⇒ Object
- .define_theme(name, colors) ⇒ Object
- .theme(name = nil) ⇒ Object
- .themes ⇒ Object
Instance Method Summary collapse
- #unicolor ⇒ Object (also: #uc)
Class Method Details
.color_for(str) ⇒ Object
25 26 27 28 29 |
# File 'lib/unicolor.rb', line 25 def color_for(str) result = colors[str.to_i(36) % colors.size] result = [result].flatten result.join(';') end |
.colorize(str) ⇒ Object
21 22 23 |
# File 'lib/unicolor.rb', line 21 def colorize(str) "\e[#{color_for(str)}m#{str}\e[0m" end |
.colors ⇒ Object
17 18 19 |
# File 'lib/unicolor.rb', line 17 def colors themes[theme] end |
.define_theme(name, colors) ⇒ Object
13 14 15 |
# File 'lib/unicolor.rb', line 13 def define_theme(name, colors) themes[name] = colors end |
.theme(name = nil) ⇒ Object
5 6 7 |
# File 'lib/unicolor.rb', line 5 def theme(name = nil) name ? @theme = name : @theme end |
.themes ⇒ Object
9 10 11 |
# File 'lib/unicolor.rb', line 9 def themes @themes ||= {} end |