Class: Array
Overview
-
internal/format/array.rb - Support for displaying an array formatted neatly.
Instance Method Summary collapse
-
#format_mysh_bullets(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Convert the array to strings with bullet points.
-
#format_mysh_columns(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Convert the array to strings with efficient columns.
-
#mysh_column_width ⇒ Object
Get the widest element of an array.
-
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
-
#puts_mysh_bullets(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Print out the array as bullet points.
-
#puts_mysh_columns(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Print out the array with efficient columns.
-
#raw_mysh_columns(page_width) ⇒ Object
(also: #format_description)
Convert the array to strings with efficient columns.
Instance Method Details
#format_mysh_bullets(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Convert the array to strings with bullet points.
Returns
-
A string.
Endemic Code Smells
-
:reek:FeatureEnvy – false positive.
57 58 59 60 61 62 63 64 65 |
# File 'lib/mysh/internal/format/array.rb', line 57 def format_mysh_bullets(page_width = Mysh::PAGE_WIDTH) return "" if empty? builder = Mysh::BulletPoints.new(page_width) each {|pair| builder.add(*pair.prepare_bullet_data)} builder.render.join("\n") end |
#format_mysh_columns(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Convert the array to strings with efficient columns.
Returns
-
A string.
Endemic Code Smells
-
:reek:FeatureEnvy – false positive.
33 34 35 |
# File 'lib/mysh/internal/format/array.rb', line 33 def format_mysh_columns(page_width = Mysh::PAGE_WIDTH) raw_mysh_columns(page_width).join("\n") end |
#mysh_column_width ⇒ Object
Get the widest element of an array.
Returns
-
The width of the widest string in the array.
40 41 42 |
# File 'lib/mysh/internal/format/array.rb', line 40 def mysh_column_width max_by {|item| item.length}.length end |
#prepare_bullet_data ⇒ Object
Get data ready for being in a bullet point.
68 69 70 71 72 73 74 |
# File 'lib/mysh/internal/format/array.rb', line 68 def prepare_bullet_data if length < 2 ["*", self[0]] else self end end |
#puts_mysh_bullets(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Print out the array as bullet points.
48 49 50 |
# File 'lib/mysh/internal/format/array.rb', line 48 def puts_mysh_bullets(page_width = Mysh::PAGE_WIDTH) puts format_mysh_bullets(page_width) end |
#puts_mysh_columns(page_width = Mysh::PAGE_WIDTH) ⇒ Object
Print out the array with efficient columns.
9 10 11 |
# File 'lib/mysh/internal/format/array.rb', line 9 def puts_mysh_columns(page_width = Mysh::PAGE_WIDTH) puts format_mysh_columns(page_width) end |
#raw_mysh_columns(page_width) ⇒ Object Also known as: format_description
Convert the array to strings with efficient columns.
Returns
-
An array of strings.
Endemic Code Smells
-
:reek:FeatureEnvy – false positive.
18 19 20 21 22 23 24 |
# File 'lib/mysh/internal/format/array.rb', line 18 def raw_mysh_columns(page_width) builder = Mysh::ColumnizedPage.new(page_width) each {|item| builder.add(item)} builder.render end |