Class: Gorgyrella::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgyrella/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

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

#sectionsObject (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_sectionObject



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