Module: VMCStringExtensions
- Included in:
- String
- Defined in:
- lib/cli/core_ext.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #bold ⇒ Object
- #colorize(color_code) ⇒ Object
- #green ⇒ Object
- #red ⇒ Object
- #truncate(limit = 30) ⇒ Object
- #yellow ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
96 97 98 |
# File 'lib/cli/core_ext.rb', line 96 def blank? self =~ /^\s*$/ end |
#bold ⇒ Object
84 85 86 |
# File 'lib/cli/core_ext.rb', line 84 def bold colorize("\e[0m\e[1m") end |
#colorize(color_code) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/cli/core_ext.rb', line 88 def colorize(color_code) if VMC::Cli::Config.colorize "#{color_code}#{self}\e[0m" else self end end |
#green ⇒ Object
76 77 78 |
# File 'lib/cli/core_ext.rb', line 76 def green colorize("\e[0m\e[32m") end |
#red ⇒ Object
72 73 74 |
# File 'lib/cli/core_ext.rb', line 72 def red colorize("\e[0m\e[31m") end |
#truncate(limit = 30) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cli/core_ext.rb', line 100 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 |
#yellow ⇒ Object
80 81 82 |
# File 'lib/cli/core_ext.rb', line 80 def yellow colorize("\e[0m\e[33m") end |