Class: Fbe::Award::Bylaw

Inherits:
Object
  • Object
show all
Defined in:
lib/fbe/award.rb

Overview

A bylaw.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBylaw

Returns a new instance of Bylaw.



342
343
344
345
346
# File 'lib/fbe/award.rb', line 342

def initialize
  @lines = []
  @intro = ''
  @lets = {}
end

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



340
341
342
# File 'lib/fbe/award.rb', line 340

def vars
  @vars
end

Instance Method Details

#intro(text) ⇒ Object



352
353
354
# File 'lib/fbe/award.rb', line 352

def intro(text)
  @intro = text
end

#let(key, value) ⇒ Object



361
362
363
# File 'lib/fbe/award.rb', line 361

def let(key, value)
  @lets[key] = value
end

#line(line) ⇒ Object



356
357
358
359
# File 'lib/fbe/award.rb', line 356

def line(line)
  line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" }
  @lines << line
end

#markdownObject



365
366
367
368
369
370
371
372
373
374
375
# File 'lib/fbe/award.rb', line 365

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

#revert(num) ⇒ Object



348
349
350
# File 'lib/fbe/award.rb', line 348

def revert(num)
  @lines.slice!(-num, num)
end