class XfOOrth::BulletPoints
A class to display data in bullet points.
Public Class Methods
new(page_width)
click to toggle source
Prepare a blank slate.
# File lib/fOOrth/library/formatting/bullets.rb, line 10 def initialize(page_width) @page_width = page_width @bullet_data = [] end
Public Instance Methods
add(bullet, *items)
click to toggle source
Add items to these bullet points.
# File lib/fOOrth/library/formatting/bullets.rb, line 16 def add(bullet, *items) items.each do |item| @bullet_data << [bullet.to_s, item] bullet = "" end end
render()
click to toggle source
Render the bullet points as an array of strings.
# File lib/fOOrth/library/formatting/bullets.rb, line 24 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
Private Instance Methods
get_key_length()
click to toggle source
Allowing for a trailing space, how large is the largest bullet?
# File lib/fOOrth/library/formatting/bullets.rb, line 38 def get_key_length (@bullet_data.max_by {|line| line[0].length})[0].length + 1 end
render_bullet(key, item)
click to toggle source
Render one bullet point.
# File lib/fOOrth/library/formatting/bullets.rb, line 43 def render_bullet(key, item) result = [] item.format_description(@page_width - @key_length - 1).each do |desc_line| result << key.ljust(@key_length) + desc_line key = "" end result end