Class: Fbe::Award::Bylaw
- Inherits:
-
Object
- Object
- Fbe::Award::Bylaw
- Defined in:
- lib/fbe/award.rb
Overview
A bylaw.
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
-
#initialize ⇒ Bylaw
constructor
A new instance of Bylaw.
- #intro(text) ⇒ Object
- #let(key, value) ⇒ Object
- #line(line) ⇒ Object
- #markdown ⇒ Object
- #revert(num) ⇒ Object
Constructor Details
#initialize ⇒ Bylaw
Returns a new instance of Bylaw.
313 314 315 316 317 |
# File 'lib/fbe/award.rb', line 313 def initialize @lines = [] @intro = '' @lets = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
311 312 313 |
# File 'lib/fbe/award.rb', line 311 def vars @vars end |
Instance Method Details
#intro(text) ⇒ Object
323 324 325 |
# File 'lib/fbe/award.rb', line 323 def intro(text) @intro = text end |
#let(key, value) ⇒ Object
332 333 334 |
# File 'lib/fbe/award.rb', line 332 def let(key, value) @lets[key] = value end |
#line(line) ⇒ Object
327 328 329 330 |
# File 'lib/fbe/award.rb', line 327 def line(line) line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" } @lines << line end |
#markdown ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/fbe/award.rb', line 336 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
319 320 321 |
# File 'lib/fbe/award.rb', line 319 def revert(num) @lines.slice!(-num, num) end |