Class: FormatOutput::BulletPointBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/format_output/builders/bullet_builder.rb

Overview

A class to build bullet points for display.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BulletPointBuilder

Prepare a blank slate.



10
11
12
13
14
15
# File 'lib/format_output/builders/bullet_builder.rb', line 10

def initialize(options)
  @body        = ::FormatOutput.width(options)
  @pad         = ::FormatOutput.pad(options)
  @bullet_data = []
  @key_length  = nil
end

Instance Method Details

#add(bullet, *items) ⇒ Object

Add items to these bullet points.



18
19
20
21
22
23
# File 'lib/format_output/builders/bullet_builder.rb', line 18

def add(bullet, *items)
  items.each do |item|
    @bullet_data << [bullet.to_s, item]
    bullet = ""
  end
end

#renderObject

Render the bullet points as an array of strings.



26
27
28
29
30
31
32
33
34
35
# File 'lib/format_output/builders/bullet_builder.rb', line 26

def render
  @key_length, results = get_key_length, []

  @bullet_data.each do |key, item|
    results.concat(render_bullet(key, item))
  end

  @bullet_data = []
  results
end