class Fbe::Award::Bylaw

It produces Markdown-formatted output describing how awards are calculated.
introductions, calculation steps, and variable substitutions.
This class builds textual descriptions of award bylaws including
A class for generating human-readable bylaws.

def initialize

bylaw = Fbe::Award::Bylaw.new
@example

Creates a new empty bylaw.
def initialize
  @lines = []
  @intro = ''
  @lets = {}
end

def intro(text)

Returns:
  • (String) - The introductory text

Parameters:
  • text (String) -- The introductory text to set
def intro(text)
  @intro = text
end

def let(key, value)

Returns:
  • (Object) - The assigned value

Parameters:
  • value (Object) -- The value to associate with the variable
  • key (Symbol) -- The variable name
def let(key, value)
  @lets[key] = value
end

def line(line)

Returns:
  • (nil) -

Parameters:
  • line (String) -- The line of text to add
def line(line)
  line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" }
  @lines << line
end

def markdown

Returns:
  • (String) - The bylaw formatted as Markdown text
def markdown
  pars = []
  pars << "#{@intro}." unless @intro.empty?
  pars << 'Here is how it\'s calculated:'
  if @lines.size == 1
    pars << "Just #{@lines.first}."
  else
    pars += @lines.each_with_index.map { |t, i| "#{i.zero? ? 'First' : 'Then'}, #{t}." }
  end
  pars.join(' ').gsub('. Then, award ', ', and award ').gsub(/\s{2,}/, ' ')
end

def revert(num)

Returns:
  • (Array) - The removed lines

Parameters:
  • num (Integer) -- The number of lines to remove from the end
def revert(num)
  @lines.slice!(-num, num)
end