Module: Unicolor

Defined in:
lib/unicolor.rb,
lib/unicolor/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

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

.colorsObject



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

.themesObject



9
10
11
# File 'lib/unicolor.rb', line 9

def themes
  @themes ||= {}
end

Instance Method Details

#unicolorObject Also known as: uc



33
34
35
# File 'lib/unicolor.rb', line 33

def unicolor
  Unicolor.colorize(self.to_s)
end