Class: Gorgyrella::Builder
- Inherits:
-
Object
- Object
- Gorgyrella::Builder
- Defined in:
- lib/gorgyrella/builder.rb
Instance Attribute Summary collapse
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
- #append_line(text) ⇒ Object
- #append_section(params = {}) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #lines_for(section_name) ⇒ Object
- #next_anonymous_section ⇒ Object
- #section(name) ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 11 |
# File 'lib/gorgyrella/builder.rb', line 5 def initialize @anonymous_section_index = 0 @line = 1 @sections = [] append_section() end |
Instance Attribute Details
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
3 4 5 |
# File 'lib/gorgyrella/builder.rb', line 3 def sections @sections end |
Instance Method Details
#append_line(text) ⇒ Object
20 21 22 23 |
# File 'lib/gorgyrella/builder.rb', line 20 def append_line(text) @sections.last[:lines] << [@line, text] @line += 1 end |
#append_section(params = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gorgyrella/builder.rb', line 33 def append_section(params = {}) command = params[:command] || 'export' section = params[:section] || next_anonymous_section new_section = { :command => command, :section => section, :file => params[:file], :format => params[:format], :language => params[:language], :lines => [] } @sections << new_section end |
#lines_for(section_name) ⇒ Object
25 26 27 |
# File 'lib/gorgyrella/builder.rb', line 25 def lines_for(section_name) section(section_name)[:lines] end |
#next_anonymous_section ⇒ Object
29 30 31 |
# File 'lib/gorgyrella/builder.rb', line 29 def next_anonymous_section (@anonymous_section_index += 1).to_s end |
#section(name) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/gorgyrella/builder.rb', line 13 def section(name) selected_sections = sections.find_all {|s| s[:section] == name} raise "section #{name} not found!" if selected_sections.size == 0 raise "section #{name} not unique!" if selected_sections.size > 1 selected_sections.first end |