Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/any-spec/string_extensions.rb

Instance Method Summary collapse

Instance Method Details

#colorize(color) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/any-spec/string_extensions.rb', line 31

def colorize(color)
  reset_string = "\e[0m"
  case color
    when :white then color_string = "\e[37m" 
    when :red then color_string = "\e[31m"
    when :green then color_string = "\e[32m"
    when :grey then color_string = "\e[90m"
  end
  return color_string + self + reset_string
end

#greenObject



19
20
21
# File 'lib/any-spec/string_extensions.rb', line 19

def green
  self.colorize(:green)
end

#greyObject



27
28
29
# File 'lib/any-spec/string_extensions.rb', line 27

def grey
  self.colorize(:grey)
end

#indent(level) ⇒ Object



3
4
5
6
7
# File 'lib/any-spec/string_extensions.rb', line 3

def indent(level)
  return self.lines.map {|line|
    ("  " * level) + line
  }.join
end

#prefix_each_line_with(string) ⇒ Object



9
10
11
12
13
# File 'lib/any-spec/string_extensions.rb', line 9

def prefix_each_line_with(string)
  return self.lines.map {|line|
    string + line
  }.join
end

#redObject



15
16
17
# File 'lib/any-spec/string_extensions.rb', line 15

def red
  self.colorize(:red)
end

#whiteObject



23
24
25
# File 'lib/any-spec/string_extensions.rb', line 23

def white
  self.colorize(:white)
end