Module: Chawan::Analyzers::Manager

Included in:
Chawan
Defined in:
lib/chawan/analyzers/manager.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object


37
38
39
# File 'lib/chawan/analyzers/manager.rb', line 37

def [](name)
  analyzer_for(name)
end

#analyzer(name = nil) ⇒ Object


8
9
10
# File 'lib/chawan/analyzers/manager.rb', line 8

def analyzer(name = nil)
  name ? analyzer_for(name) : current_analyzer
end

#analyzer_for(name) ⇒ Object


12
13
14
# File 'lib/chawan/analyzers/manager.rb', line 12

def analyzer_for(name)
  analyzers[name.to_s] or raise AnalyzerNotFound, name.to_s
end

#analyzersObject


4
5
6
# File 'lib/chawan/analyzers/manager.rb', line 4

def analyzers
  @analyzers ||= {}
end

#current_analyzerObject


16
17
18
# File 'lib/chawan/analyzers/manager.rb', line 16

def current_analyzer
  @analyzer or raise AnalyzerNotSetup
end

#define_analyzer(name, analyzer) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chawan/analyzers/manager.rb', line 20

def define_analyzer(name, analyzer)
  analyzers[name] = analyzer

  unless respond_to?(name)
    eval(<<-RUBY)
      def Chawan.#{name}
        Chawan['#{name}']
      end
    RUBY
  end
end

#setup(name, setter = nil) ⇒ Object


32
33
34
35
# File 'lib/chawan/analyzers/manager.rb', line 32

def setup(name, setter = nil)
  define_analyzer(name.to_s, setter) if setter
  @analyzer = analyzer_for(name)
end