Class: FisherClassifier::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fisher_classifier/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Config



4
5
6
7
8
9
10
11
# File 'lib/fisher_classifier/config.rb', line 4

def initialize(block)
  @config = {
    weight: 1.0,
    ap: 0.5
  }
  @methods = {}
  instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, value = nil, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/fisher_classifier/config.rb', line 25

def method_missing(key, value = nil, &block)
  if block_given?
    @methods[key] = block
  else
    @config[key] = value
  end
end

Instance Method Details

#call(name, *args) ⇒ Object



19
20
21
22
23
# File 'lib/fisher_classifier/config.rb', line 19

def call(name, *args)
  raise "'#{name}' mehtod does not defined in config" unless @methods.has_key? name

  @methods[name].call *args
end

#get(key) ⇒ Object



13
14
15
16
17
# File 'lib/fisher_classifier/config.rb', line 13

def get(key)
  raise "'#{key}' value does not defined in config" unless @config.has_key? key

  @config[key]
end