Class: Booby::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/booby/parser.rb

Overview

Public: Generic configuration parser. You shouldn’t access this class directly, use Booby#open and Booby#prepare instead.

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Public: Initializer.

source - The String source code of a config file.



9
10
11
# File 'lib/booby/parser.rb', line 9

def initialize(source)
  @source = source
end

Instance Method Details

#parse_with(processor) ⇒ Object

Public: Parses initialized config source with using given processor class. The processor class must implement #process instance method.

processor - The processor class to parse source with.

Returns processor instance that contains parsed data.



19
20
21
22
23
24
# File 'lib/booby/parser.rb', line 19

def parse_with(processor)
  processor.new.tap do |p|
    @__root_processor = @__current_processor = p
    @source.split(/$/).each_with_index { |line, i| process_line(line, i) }
  end
end