Class: Ruco::ArrayProcessor
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #close_tag(name, position) ⇒ Object
- #end_parsing(name) ⇒ Object
-
#initialize ⇒ ArrayProcessor
constructor
A new instance of ArrayProcessor.
- #inspect ⇒ Object
- #new_line(line) ⇒ Object
- #open_tag(name, position) ⇒ Object
- #start_parsing(name) ⇒ Object
Constructor Details
#initialize ⇒ ArrayProcessor
Returns a new instance of ArrayProcessor.
5 6 7 8 9 10 |
# File 'lib/ruco/array_processor.rb', line 5 def initialize @line_number = -1 @lines = [] @open_elements = [] @still_open_elements = [] end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
3 4 5 |
# File 'lib/ruco/array_processor.rb', line 3 def lines @lines end |
Instance Method Details
#close_tag(name, position) ⇒ Object
17 18 19 20 21 |
# File 'lib/ruco/array_processor.rb', line 17 def close_tag(name, position) #puts "Close #{name} #{@line_number}:#{position}" open_element = @open_elements.pop || @still_open_elements.pop @lines[@line_number] << [name, open_element.last...position] end |
#end_parsing(name) ⇒ Object
47 |
# File 'lib/ruco/array_processor.rb', line 47 def end_parsing(name);end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/ruco/array_processor.rb', line 49 def inspect @lines end |
#new_line(line) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruco/array_processor.rb', line 23 def new_line(line) #puts "Line #{line}" # close elements only opened in last line @open_elements.each do |name, position| @lines[@line_number] << [name, position...@line.size] end # surround last line in still open elements from previouse lines @still_open_elements.each do |name,_| @lines[@line_number] << [name, 0...@line.size] end # mark open as 'still open' # and let them start on column 0 -> if closed in this line its 0...position @still_open_elements += @open_elements.map{|name,_| [name,0]} @open_elements = [] # proceed with next line @line = line @line_number += 1 @lines[@line_number] = [] end |
#open_tag(name, position) ⇒ Object
12 13 14 15 |
# File 'lib/ruco/array_processor.rb', line 12 def open_tag(name, position) #puts "Open #{name} #{@line_number}:#{position}" @open_elements << [name, position] end |
#start_parsing(name) ⇒ Object
46 |
# File 'lib/ruco/array_processor.rb', line 46 def start_parsing(name);end |