Class: WordMatch

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/textquery/textquery.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) accept(&block)



55
56
57
# File 'lib/textquery/textquery.rb', line 55

def accept(&block)
  block.call(:value, text_value)
end

- (Object) eval(text, opt)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/textquery/textquery.rb', line 27

def eval(text, opt)
  query = RegExp.escape(text_value)
  qkey  = query + opt[:delim]

  if not @@regex[qkey]
    fuzzy = FUZZY.match(query)

    q = []
    q.push "."                                    if fuzzy[2]
    q.push fuzzy[1].nil? ? "*" : "{#{fuzzy[1]}}"  if fuzzy[2]
    q.push fuzzy[3]
    q.push "."                                    if fuzzy[4]
    q.push fuzzy[5].nil? ? "*" : "{#{fuzzy[5]}}"  if fuzzy[4]
    q = q.join

    regex = "(^|#{opt[:delim]})#{q}(#{opt[:delim]}|$)"

    @@regex[qkey] = RegExp.new(regex, :options => RegExp::IGNORECASE)
    @@regex_case[qkey] = RegExp.new(regex, nil)
  end

  if opt[:ignorecase]
    not @@regex[qkey].match(text).nil?
  else
    not @@regex_case[qkey].match(text).nil?
  end
end