Module: Card::Query::Value::MatchValue
- Included in:
- Card::Query::Value
- Defined in:
- card/lib/card/query/value/match_value.rb
Overview
handling for match operator
Instance Method Summary collapse
-
#escape_regexp_characters ⇒ Object
-
#exact_name_match(field) ⇒ Object
-
#match_field(field) ⇒ Object
-
#match_prefix ⇒ Object
-
#match_sql(field) ⇒ Object
-
#match_term ⇒ Object
-
#match_value ⇒ Object
-
#parse_match_term_and_prefix ⇒ Object
if search val is prefixed with “~~”, it is a MYSQL regexp (and will be passed through).
Instance Method Details
#escape_regexp_characters ⇒ Object
60 61 62 |
# File 'card/lib/card/query/value/match_value.rb', line 60 def escape_regexp_characters match_term.gsub!(/(\W)/, '\\\\\1') end |
#exact_name_match(field) ⇒ Object
22 23 24 25 26 |
# File 'card/lib/card/query/value/match_value.rb', line 22 def exact_name_match field return false unless match_prefix == "=" && field.to_sym == :name "#{field_sql field} = #{quote match_term.to_name.key}" end |
#match_field(field) ⇒ Object
28 29 30 31 |
# File 'card/lib/card/query/value/match_value.rb', line 28 def match_field field fld = field.to_sym == :name ? "name" : standardize_field(field) "#{@query.table_alias}.#{fld}" end |
#match_prefix ⇒ Object
42 43 44 |
# File 'card/lib/card/query/value/match_value.rb', line 42 def match_prefix @match_prefix || (parse_match_term_and_prefix && @match_prefix) end |
#match_sql(field) ⇒ Object
17 18 19 20 |
# File 'card/lib/card/query/value/match_value.rb', line 17 def match_sql field exact_name_match(field) || "#{match_field field} #{connection.match match_value}" end |
#match_term ⇒ Object
38 39 40 |
# File 'card/lib/card/query/value/match_value.rb', line 38 def match_term @match_term || (parse_match_term_and_prefix && @match_term) end |
#match_value ⇒ Object
33 34 35 36 |
# File 'card/lib/card/query/value/match_value.rb', line 33 def match_value escape_regexp_characters unless match_prefix == "~~" quote match_term end |
#parse_match_term_and_prefix ⇒ Object
if search val is prefixed with “~~”, it is a MYSQL regexp (and will be passed through)
Otherwise, all non-alphanumeric characters are escaped.
A “~” prefix is ignored.
53 54 55 56 57 58 |
# File 'card/lib/card/query/value/match_value.rb', line 53 def parse_match_term_and_prefix raw_term = Array.wrap(@value).join(" ") matches = raw_term.match self.class.match_term_and_prefix_re @match_prefix = matches[:prefix] || "" @match_term = matches[:term] || "" end |