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.



324
325
326
327
328
# File 'lib/fbe/award.rb', line 324

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

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



322
323
324
# File 'lib/fbe/award.rb', line 322

def vars
  @vars
end

Instance Method Details

#intro(text) ⇒ Object



334
335
336
# File 'lib/fbe/award.rb', line 334

def intro(text)
  @intro = text
end

#let(key, value) ⇒ Object



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

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

#line(line) ⇒ Object



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

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

#markdownObject



347
348
349
350
351
352
353
354
355
356
357
# File 'lib/fbe/award.rb', line 347

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



330
331
332
# File 'lib/fbe/award.rb', line 330

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