Module: Nyan::Colour

Defined in:
lib/nyan/colour.rb

Constant Summary collapse

TWINKLY =
"X"
MAP =
{
  "#" => "#{bright}#{black}",
  "b" => "#{dark}#{black}",
  "R" => "#{bright}#{magenta}",
  "p" => "#{dark}#{magenta}",
  "`" => "#{dark}#{yellow}",
  "o" => "#{bright}#{white}",
  "_" => "#{bright}#{white}",
  "." => "#{dark}#{white}",
  "1" => "#{bright}#{red}",
  "2" => "#{bright}#{yellow}",
  "3" => "#{bright}#{green}",
  "4" => "#{bright}#{blue}",
  "5" => "#{bright}#{magenta}",
}

Class Method Summary collapse

Class Method Details

.colourize(char) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/nyan/colour.rb', line 28

def self.colourize(char)
  escape_codes = if twinkly?(char)
                   rand > 0.5 ? "#{bright}#{white}" : "#{bright}#{black}"
                 else
                   MAP.fetch(char, "")
                 end
  "#{escape_codes}#{BLOCK}"
end

.twinkly?(char) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/nyan/colour.rb', line 24

def self.twinkly?(char)
  TWINKLY == char
end