Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/delicious-cli/blank.rb,
lib/delicious-cli/display.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
‘true’ if the string’s length is 0 (after whitespace has been stripped from the ends).
- #wrap(width = 80, chop = true) ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
‘true’ if the string’s length is 0 (after whitespace has been stripped from the ends)
37 |
# File 'lib/delicious-cli/blank.rb', line 37 def blank?; strip.size == 0; end |
#wrap(width = 80, chop = true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 |