module Rodish::Plugins::Wrap_

  1. lib/rodish/plugins/_wrap.rb

Methods

Public Instance

  1. wrap

Public Instance methods

wrap(prefix, values, separator: " ", limit: 80)

Return an array of strings, each no longer than limit, showing the prefix and all values.

[show source]
   # File lib/rodish/plugins/_wrap.rb
13        def wrap(prefix, values, separator: " ", limit: 80)
14   line = [prefix]
15   lines = [line]
16   prefix_length = length = prefix.length
17   sep_length = separator.length
18   indent = " " * prefix_length
19 
20   values.each do |value|
21     value = value.to_s
22     value_length = value.length
23     new_length = sep_length + length + value_length
24     if new_length > limit
25       line = [indent, separator, value]
26       lines << line
27       length = prefix_length
28     else
29       line << separator << value
30     end
31     length += sep_length + value_length
32   end
33 
34   lines.map{|l| l.join}
35 end