module Gorgyrella class Builder attr_reader :sections def initialize @anonymous_section_index = 0 @line = 1 @sections = [] append_section() end 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 def append_line(text) @sections.last[:lines] << [@line, text] @line += 1 end def lines_for(section_name) section(section_name)[:lines] end def next_anonymous_section (@anonymous_section_index += 1).to_s end 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 end end