Class: Slither::Generator
- Inherits:
-
Object
- Object
- Slither::Generator
- Defined in:
- lib/slither/generator.rb
Instance Method Summary collapse
- #generate(data) ⇒ Object
-
#initialize(definition) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(definition) ⇒ Generator
Returns a new instance of Generator.
4 5 6 |
# File 'lib/slither/generator.rb', line 4 def initialize(definition) @definition = definition end |
Instance Method Details
#generate(data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/slither/generator.rb', line 8 def generate(data) @builder = [] @definition.sections.each do |section| content = data[section.name] if content content = [content] unless content.is_a?(Array) raise(Slither::RequiredSectionEmptyError, "Required section '#{section.name}' was empty.") if content.empty? content.each do |row| @builder << section.format(row) end else raise(Slither::RequiredSectionEmptyError, "Required section '#{section.name}' was empty.") unless section.optional end end @builder.join("\n") end |