Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/console_colors.rb,
lib/console_colors.rb,
lib/atk/file_system.rb,
lib/atk/remove_indent.rb

Overview

Theme

Constant Summary collapse

@@colors =

generate foreground/background methods

{
    default: 39,
    black: 30,
    red: 31,
    green: 32,
    yellow: 33,
    blue: 34,
    magenta: 35,
    cyan: 36,
    white: 37,
    light_black: 90,
    light_red: 91,
    light_green: 92,
    light_yellow: 93,
    light_blue: 94,
    light_magenta: 95,
    light_cyan: 96,
    light_white: 97,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.color_samplesObject



70
71
72
73
74
# File 'lib/console_colors.rb', line 70

def self.color_samples
    for background, foreground in @@colors.keys.permutation(2)
        eval("puts ' #{foreground} on_#{background} '.rjust(32).#{foreground}.on_#{background}")
    end
end

Instance Method Details

#/(next_string) ⇒ Object

this is for easy creation of cross-platform filepaths ex: “foldername”/“filename”



16
17
18
19
20
21
22
23
24
25
# File 'lib/atk/file_system.rb', line 16

def /(next_string)
    if OS.is?("windows")
        next_string_without_leading_or_trailing_slashes = next_string.gsub(/(^\\|^\/|\\$|\/$)/,"")
        output = self + "\\" + next_string
        # replace all forward slashes with backslashes
        output.gsub(/\//,"\\")
    else
        File.join(self, next_string)
    end
end

#color_as(kind) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/console_colors.rb', line 82

def color_as(kind)
    case kind
        when :error
            " #{self} ".white.on_red
        when :code
            " #{self} ".light_blue.on_black
        when :key_term
            " #{self} ".yellow.on_black
        when :title
            " #{self} ".green.on_black
        when :argument, :message
            " #{self} ".cyan.on_black
        when :optional
            " #{self} ".light_magenta.on_black
        when :good
            " #{self} ".green.on_black
        when :bad
            " #{self} ".red.on_black
        else
            " #{self} ".cyan.on_black
    end
end

#remove_indentObject

this is for having docstrings that get their indent removed this is used frequently for multi-line strings and error messages example usage puts <<-HEREDOC.remove_indent This command does such and such.

this part is extra indented

HEREDOC



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

def remove_indent
    gsub(/^[ \t]{#{self.match(/^[ \t]*/)[0].length}}/, '')
end

#unstyleObject



66
67
68
# File 'lib/console_colors.rb', line 66

def unstyle
    self.gsub!(/\e\[([;0-9]+)m/,"") || self
end