class String
Colourized hilite…
Public Instance Methods
blank?()
click to toggle source
‘true’ if the string’s length is 0 (after whitespace has been stripped from the ends)
# File lib/delicious-cli/blank.rb, line 37 def blank?; strip.size == 0; end
hilite(words, color=:white)
click to toggle source
# File lib/delicious-cli/display.rb, line 13 def hilite(words, color=:white) return self.send(color) if words.nil? escaped_words = words.map { |word| Regexp.escape(word) } matcher = /(#{escaped_words.join('|')})/io chunks = self.to_s.split(matcher) chunks.map do |chunk| if chunk =~ matcher chunk.black.on_yellow else chunk.send(color) end end.join('') end
wrap(width=80, chop=true)
click to toggle source
# File lib/delicious-cli/display.rb, line 50 def wrap(width=80, chop=true) if (lines = self.split("\n")).size > 1 return lines.map { |line| line.wrap(width, chop) }.flatten end lines = [] left = 0 loop do edge = left + width - 1 right = self.rindex(/\s+|$/, edge) if right.nil? or right < left if chop right = edge else right = self.index(/\s+|$/, edge) end end line = self[left...right] lines << line.strip left = self.index(/[^\s]|$/, right) break if right >= (self.size-1) end lines end