Module: StringExtensions

Included in:
String
Defined in:
lib/wasp/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/wasp/core_ext.rb', line 91

def blank?
    self =~ /^\s*$/
end

#boldObject



83
84
85
# File 'lib/wasp/core_ext.rb', line 83

def bold
    colorize("\e[0m\e[1m")
end

#colorize(color_code) ⇒ Object



87
88
89
# File 'lib/wasp/core_ext.rb', line 87

def colorize(color_code)
    "#{color_code}#{self}\e[0m"
end

#greenObject



75
76
77
# File 'lib/wasp/core_ext.rb', line 75

def green
    colorize("\e[0m\e[32m")
end

#redObject



71
72
73
# File 'lib/wasp/core_ext.rb', line 71

def red
    colorize("\e[0m\e[31m")
end

#truncate(limit = 30) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/wasp/core_ext.rb', line 95

def truncate(limit = 30)
    return "" if self.blank?
    etc = "..."
    stripped = self.strip[0..limit]
    if stripped.length > limit
        stripped.gsub(/\s+?(\S+)?$/, "") + etc
    else
        stripped
    end
end

#yellowObject



79
80
81
# File 'lib/wasp/core_ext.rb', line 79

def yellow
    colorize("\e[0m\e[33m")
end