Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/na/array.rb
Overview
Extensions to Ruby’s Array class for todo management and formatting.
Direct Known Subclasses
Instance Method Summary collapse
-
#remove_bad ⇒ Array
Like Array#compact – removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items.
-
#wrap(width, indent, color) ⇒ Array, String
Wrap each string in the array to the given width and indent, with color.
Instance Method Details
#remove_bad ⇒ Array
Like Array#compact – removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items
15 16 17 |
# File 'lib/na/array.rb', line 15 def remove_bad compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?) end |
#wrap(width, indent, color) ⇒ Array, String
Wrap each string in the array to the given width and indent, with color
27 28 29 30 31 32 33 34 |
# File 'lib/na/array.rb', line 27 def wrap(width, indent, color) return map { |l| "#{color} #{l.wrap(width, 2)}" } if width < 60 map! do |l| "#{color}#{' ' * indent}• #{l.wrap(width, indent)}{x}" end "\n#{join("\n")}" end |