Class: String
- Defined in:
- lib/format_output/bullets.rb,
lib/format_output/word_wrap.rb
Overview
Support for displaying string data formatted with word wrap.
Instance Method Summary collapse
-
#do_format_output_bullet_detail(input, body, pad) ⇒ Object
Do the formatting legwork.
-
#format_output_bullet_detail(options = {}) ⇒ Object
(also: #format_output_raw_word_wrap)
Create a bullet point description from this string.
-
#format_output_split_if_huge(buffer, body, pad) ⇒ Object
Split up a overlong blob of text.
-
#format_output_split_if_over(buffer, body, pad, word) ⇒ Object
Split if adding a word goes over a little.
-
#format_output_word_wrap(options = {}) ⇒ Object
Convert the string to a string with bullet points.
-
#puts_format_output_word_wrap(options = {}) ⇒ Object
Print out the string with word wrap.
Instance Method Details
#do_format_output_bullet_detail(input, body, pad) ⇒ Object
Do the formatting legwork. Returns: An array of strings.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 = {}) ⇒ Object Also known as: format_output_raw_word_wrap
Create a bullet point description from this string. Returns: An array of strings.
78 79 80 81 82 83 |
# File 'lib/format_output/bullets.rb', line 78 def format_output_bullet_detail( = {}) body = ::FormatOutput.width() pad = ::FormatOutput.pad() do_format_output_bullet_detail(split(' ').each, body, pad) end |
#format_output_split_if_huge(buffer, body, pad) ⇒ Object
Split up a overlong blob of text. Note: self is the result string from format_output_split_if_over. Returns: A string.
125 126 127 128 129 130 131 132 133 |
# 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) ⇒ Object
Split if adding a word goes over a little. Note: self is the build string from do_format_output_bullet_detail. Returns: A string.
109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 = {}) ⇒ Object
Convert the string to a string with bullet points. Returns: A string.
42 43 44 |
# File 'lib/format_output/word_wrap.rb', line 42 def format_output_word_wrap( = {}) format_output_raw_word_wrap().join("\n") end |
#puts_format_output_word_wrap(options = {}) ⇒ Object
Print out the string with word wrap.
36 37 38 |
# File 'lib/format_output/word_wrap.rb', line 36 def puts_format_output_word_wrap( = {}) puts format_output_word_wrap() end |