class String

Support for displaying string data formatted in bullet points.

Support for displaying string data formatted with word wrap.

Public Instance Methods

do_format_output_bullet_detail(input, body, pad) click to toggle source

Do the formatting legwork. Returns: An array of strings.

# File lib/format_output/bullets.rb, line 87
def do_format_output_bullet_detail(input, body, pad)
  buffer, build, empty = [], "", false

  # Grab "words" of input, splitting off lines as needed.
  # Note: This loop exits when input.next runs out of data.
  loop do
    build = build.format_output_split_if_over(buffer, body, pad, input.next)
                 .format_output_split_if_huge(buffer, body, pad)

    empty = build.empty?
  end

  unless empty
    buffer << pad + build
  end

  buffer
end
format_output_bullet_detail(options = {}) click to toggle source

Create a bullet point description from this string. Returns: An array of strings.

# File lib/format_output/bullets.rb, line 78
def format_output_bullet_detail(options = {})
  body = ::FormatOutput.width(options)
  pad  = ::FormatOutput.pad(options)

  do_format_output_bullet_detail(split(' ').each, body, pad)
end
Also aliased as: format_output_raw_word_wrap
format_output_raw_word_wrap(options = {})

Convert the string to an array of strings with word wrap. Returns: An array of strings. This method is a duplicate of a bullet point method with a new name.

format_output_split_if_huge(buffer, body, pad) click to toggle source

Split up a overlong blob of text. Note: self is the result string from format_output_split_if_over. Returns: A string.

# File lib/format_output/bullets.rb, line 125
def format_output_split_if_huge(buffer, body, pad)

  # Slice away any excess text into lines in the buffer.
  while length >= body
    buffer << pad + slice!(0, body)
  end

  self
end
format_output_split_if_over(buffer, body, pad, word) click to toggle source

Split if adding a word goes over a little. Note: self is the build string from do_format_output_bullet_detail. Returns: A string.

# File lib/format_output/bullets.rb, line 109
def format_output_split_if_over(buffer, body, pad, word)
  word.prepend(" ") unless empty? #Add a space except for the first word.

  word_len = word.length

  if (length + word_len) >= body && word_len < body
    buffer << pad + self    # Line done, add to buffer.
    word.lstrip             # Start of a new line, remove the leading space.
  else
    self + word
  end
end
format_output_word_wrap(options = {}) click to toggle source

Convert the string to a string with bullet points. Returns: A string.

# File lib/format_output/word_wrap.rb, line 42
def format_output_word_wrap(options = {})
  format_output_raw_word_wrap(options).join("\n")
end
puts_format_output_word_wrap(options = {}) click to toggle source

Print out the string with word wrap.

# File lib/format_output/word_wrap.rb, line 36
def puts_format_output_word_wrap(options = {})
  puts format_output_word_wrap(options)
end