Class: Wice::FilterConditionsGeneratorString

Inherits:
FilterConditionsGenerator show all
Defined in:
lib/filter_conditions_generators.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from FilterConditionsGenerator

#criteria

Instance Method Summary collapse

Methods inherited from FilterConditionsGenerator

#initialize

Constructor Details

This class inherits a constructor from Wice::FilterConditionsGenerator

Instance Method Details

#generate_conditions(opts) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/filter_conditions_generators.rb', line 73

def generate_conditions(opts)   #:nodoc:
  negation = nil
  if opts.kind_of? String
    string_fragment = opts
  elsif (opts.kind_of? Hash) && opts.has_key?(:v)
    string_fragment = opts[:v]
    #negation = opts[:n] == '1' ? 'NOT' : ''
  else
    Wice.log "invalid parameters for the grid string filter - must be a string: #{opts.inspect} or a Hash with keys :v and :n"
    return false
  end
  if string_fragment.empty?
    Wice.log "invalid parameters for the grid string filter - empty string"
    return false
  end
  if string_fragment.starts_with?('/')
    string_fragment = string_fragment[1..-1]
  else
    special_chars = '|()[]{}+\^$*?.'
    string_fragment = string_fragment.gsub( /([\|\(\)\[\]\{\}\+\^\\\$\*\?\.])/ )  { |s| '\\' + s}
  end
    
  @criteria = @criteria.where(@field.name.to_s => /#{string_fragment}/i)
  return true
end