class Babik::Selection::Operation::IRegex

Match by case insensitive regex

Public Class Methods

new(field, value) click to toggle source
Calls superclass method Babik::Selection::Operation::Regex::new
# File lib/babik/queryset/lib/selection/operation/regex.rb, line 39
def initialize(field, value)
  value = value.inspect[1..-2] if value.class == Regexp
  value = value[1..-2] if value.class == String && value[0] == '/' && value[-1] == '/'
  value = "(?i)#{value}" if db_engine == 'sqlite3'
  field = "LOWER(#{field})" if db_engine == 'mysql2'
  super(field, value)
end

Public Instance Methods

operator() click to toggle source
# File lib/babik/queryset/lib/selection/operation/regex.rb, line 47
def operator
  dbms_adapter = db_engine
  return 'REGEXP' if dbms_adapter == 'mysql2'
  return '~*' if dbms_adapter == 'postgresql'
  return 'REGEXP' if dbms_adapter == 'sqlite3'
  raise NotImplementedError, "Invalid dbms #{dbms_adapter}. Only mysql, postgresql, and sqlite3 are accepted"
end