Class: Array
- Defined in:
- lib/fOOrth/library/clone_library.rb,
lib/fOOrth/library/formatting/array.rb
Overview
-
library/formatting/array.rb - Array support for displaying data formatted neatly.
Instance Method Summary collapse
-
#foorth_column_width ⇒ Object
Get the widest element of an array.
-
#foorth_format_bullets(page_width) ⇒ Object
Convert the array to strings with bullet points.
-
#format_description(page_width) ⇒ Object
Convert the array to a bullet point description.
-
#format_foorth_columns(page_length, page_width) ⇒ Object
Convert the array to strings with efficient columns.
-
#full_clone_exclude ⇒ Object
The full clone data member clone exclusion control.
-
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
-
#puts_foorth_bullets(page_width) ⇒ Object
Print out the array as bullet points.
-
#puts_foorth_columns(page_length, page_width) ⇒ Object
Print out the array with efficient columns.
Instance Method Details
#foorth_column_width ⇒ Object
Get the widest element of an array.
Returns
-
The width of the widest string in the array.
29 30 31 |
# File 'lib/fOOrth/library/formatting/array.rb', line 29 def foorth_column_width (self.max_by {|item| item.length}).length end |
#foorth_format_bullets(page_width) ⇒ Object
Convert the array to strings with bullet points.
Returns
-
A string
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fOOrth/library/formatting/array.rb', line 62 def foorth_format_bullets(page_width) return "" if empty? builder = XfOOrth::BulletPoints.new(page_width) self.each do |pair| builder.add(*pair.prepare_bullet_data) end builder.render.join("\n").freeze end |
#format_description(page_width) ⇒ Object
Convert the array to a bullet point description.
Returns
-
An array of strings.
77 78 79 |
# File 'lib/fOOrth/library/formatting/array.rb', line 77 def format_description(page_width) format_foorth_pages(false, page_width)[0] || [] end |
#format_foorth_columns(page_length, page_width) ⇒ Object
Convert the array to strings with efficient columns.
Returns
-
A string.
18 19 20 21 22 23 24 |
# File 'lib/fOOrth/library/formatting/array.rb', line 18 def format_foorth_columns(page_length, page_width) format_foorth_pages(page_length, page_width) .map {|page| page << ""} .flatten[0...-1] .join("\n") .freeze end |
#full_clone_exclude ⇒ Object
The full clone data member clone exclusion control
54 55 56 57 58 |
# File 'lib/fOOrth/library/clone_library.rb', line 54 def full_clone_exclude vm = Thread.current[:vm] self.foorth_exclude(vm) vm.pop end |
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
82 83 84 85 86 87 88 |
# File 'lib/fOOrth/library/formatting/array.rb', line 82 def prepare_bullet_data if length < 2 ["*", self[0]] else self end end |
#puts_foorth_bullets(page_width) ⇒ Object
Print out the array as bullet points.
55 56 57 |
# File 'lib/fOOrth/library/formatting/array.rb', line 55 def puts_foorth_bullets(page_width) puts foorth_format_bullets(page_width) end |
#puts_foorth_columns(page_length, page_width) ⇒ Object
Print out the array with efficient columns.
9 10 11 12 13 |
# File 'lib/fOOrth/library/formatting/array.rb', line 9 def puts_foorth_columns(page_length, page_width) format_foorth_pages(page_length, page_width).each do |page| puts page, "" end end |