Module: Deli::Param::String

Instance Method Summary collapse

Instance Method Details

#parse(value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/deli/param.rb', line 36

def parse(value)
  arrays = value.split(/(?:[\s|\+]OR[\s|\+]|\||,)/).map do |node|
    values = []
    
    # ([\+\-\^]?[\w@\-_\s\d\.\$]+|-?\'[\w@-_\s\d\+\.\$]+\')
    node.scan(/([\+\-\^]?[\w@_\s\d\.\$]+|-?\'[\w@-_\s\d\+\.\$]+\')/).flatten.each do |token|
      token.gsub!(/^\+?-+/, "")
      negation = $& && $&.length > 0
      token.gsub!(/^\'(.+)\'$/, "\\1")
      exact    = $& && $&.length > 0
      
      if negation
        operators = [exact ? "!=" : "!~"]
      else
        operators = [exact ? "=" : "=~"]
      end
      
      operators << "^" if token =~ /^\+?\-?\^/
      operators << "$" if token =~ /\$$/
      
      values    << parse_value(clean(token), operators)
    end
    
    values
  end
end