Class: Array

Inherits:
Object show all
Defined in:
lib/format_output/bullets.rb,
lib/format_output/columns.rb,
lib/format_output/word_wrap.rb

Overview

Support for displaying an array of strings formatted with word wrap.

Instance Method Summary collapse

Instance Method Details

#format_output_bullet_detailObject

This method is a duplicate of a column method with a new name.



33
# File 'lib/format_output/bullets.rb', line 33

alias :format_output_bullet_detail :format_output_raw_columns

#format_output_bullets(options = {}) ⇒ Object

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



14
15
16
# File 'lib/format_output/bullets.rb', line 14

def format_output_bullets(options = {})
  format_output_raw_bullets(options).join("\n")
end

#format_output_columns(options = {}) ⇒ Object

Convert the array to a string with efficient columns. Returns: A string. Endemic Code Smells reek:FeatureEnvy – false positive.



15
16
17
# File 'lib/format_output/columns.rb', line 15

def format_output_columns(options = {})
  format_output_raw_columns(options).join("\n")
end

#format_output_greatest_widthObject

Get the widest element of an array. Returns: The width of the widest string in the array.



33
34
35
# File 'lib/format_output/columns.rb', line 33

def format_output_greatest_width
  max_by {|item| item.length}.length
end

#format_output_prepare_bullet_detailObject

Get data ready for being in a bullet point.



36
37
38
39
40
41
42
# File 'lib/format_output/bullets.rb', line 36

def format_output_prepare_bullet_detail
  if length < 2
    ["*", self[0]]
  else
    self
  end
end

#format_output_raw_bullets(options = {}) ⇒ Object

Convert the array to strings with bullet points. Returns: An array of strings.



20
21
22
23
24
25
26
27
28
# File 'lib/format_output/bullets.rb', line 20

def format_output_raw_bullets(options = {})
  return [""] if empty?

  builder = FormatOutput::BulletPointBuilder.new(options)

  each {|pair| builder.add(*pair.format_output_prepare_bullet_detail)}

  builder.render
end

#format_output_raw_columns(options = {}) ⇒ Object

Convert the array to strings with efficient columns. Returns: An array of strings.



21
22
23
24
25
26
27
# File 'lib/format_output/columns.rb', line 21

def format_output_raw_columns(options = {})
  builder = FormatOutput::ColumnBuilder.new(options)

  each {|item| builder.add(item)}

  builder.render
end

#format_output_raw_word_wrap(options = {}) ⇒ Object

Convert the array to strings with word wrap. Returns: An array of strings.



19
20
21
22
23
24
25
26
27
28
# File 'lib/format_output/word_wrap.rb', line 19

def format_output_raw_word_wrap(options = {})
  result = []

  each do |item|
    result.concat(item.to_s.format_output_raw_word_wrap(options))
    result << ""
  end

  result
end

#format_output_word_wrap(options = {}) ⇒ Object

Convert the array to a string with word wrap. Returns: A string.



13
14
15
# File 'lib/format_output/word_wrap.rb', line 13

def format_output_word_wrap(options = {})
  format_output_raw_word_wrap(options).join("\n")
end

#puts_format_output_bullets(options = {}) ⇒ Object

Print out the array as bullet points.



8
9
10
# File 'lib/format_output/bullets.rb', line 8

def puts_format_output_bullets(options = {})
  puts format_output_bullets(options)
end

#puts_format_output_columns(options = {}) ⇒ Object

Print out the array with efficient columns.



8
9
10
# File 'lib/format_output/columns.rb', line 8

def puts_format_output_columns(options = {})
  puts format_output_columns(options)
end

#puts_format_output_word_wrap(options = {}) ⇒ Object

Print out the array with word wrap.



7
8
9
# File 'lib/format_output/word_wrap.rb', line 7

def puts_format_output_word_wrap(options = {})
  puts format_output_word_wrap(options).join("\n")
end