UNPKG

534 Btext/coffeescriptView Raw
1
2class TokenMatcher
3
4 @match: ( @file, @tokens ) ->
5
6 highestscore = -1
7 highestordinal = -1
8
9 for ordinal, tokens of @file.tokens
10
11 if tokens.indexOf( '#' ) > -1 then continue
12
13 score = TokenMatcher.compare tokens, @tokens
14
15 if highestscore < score
16 highestscore = score
17 highestordinal = Number ordinal
18
19 return highestordinal + 1
20
21 @compare: ( tokens1, tokens2 ) ->
22
23 score = 0
24 tokens1.map (t) -> score++ if tokens2.indexOf( t ) > -1
25 return score
26
27module.exports = TokenMatcher
\No newline at end of file