Class: CodeLexer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/code-lexer/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
# File 'lib/code-lexer/config.rb', line 6

def initialize(path)
    @config = File.basename(path)
    @rules = []
    
    load_rules(path)
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



5
6
7
# File 'lib/code-lexer/config.rb', line 5

def rules
  @rules
end

Instance Method Details

#matching_rule(text) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/code-lexer/config.rb', line 13

def matching_rule(text)
    min_score = 10000
    min_couple = []
    @rules.each do |name, regex|
        if (score = (text =~ regex))
            if score < min_score
                min_score = score
                min_couple = [name, regex]
            end
        end
    end
    
    return *min_couple
end