Class: Card::Query::Value

Inherits:
Object
  • Object
show all
Includes:
Clause, MatchValue
Defined in:
lib/card/query/value.rb,
lib/card/query/value/match_value.rb

Overview

handling for CQL value clauses, eg [operator, value]

Defined Under Namespace

Modules: MatchValue

Constant Summary collapse

SQL_FIELD =
{ name: "key", content: "db_content" }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MatchValue

#escape_regexp_characters, #exact_name_match, #match_field, #match_prefix, #match_sql, #match_term, #match_value, #parse_match_term_and_prefix

Methods included from Clause

#connection, #quote, #safe_sql

Constructor Details

#initialize(rawvalue, query) ⇒ Value

Returns a new instance of Value.



12
13
14
15
16
# File 'lib/card/query/value.rb', line 12

def initialize rawvalue, query
  @query = query
  @operator, @value = parse_value rawvalue
  canonicalize_operator
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



10
11
12
# File 'lib/card/query/value.rb', line 10

def operator
  @operator
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/card/query/value.rb', line 10

def query
  @query
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/card/query/value.rb', line 10

def value
  @value
end

Class Method Details

.match_preficesObject



5
6
7
# File 'lib/card/query/value/match_value.rb', line 5

def match_prefices
  @match_prefices ||= %w[= ~]
end

.match_term_and_prefix_reObject



9
10
11
12
# File 'lib/card/query/value/match_value.rb', line 9

def match_term_and_prefix_re
  @match_term_and_prefix_re ||=
    /^(?<prefix>[#{Regexp.escape match_prefices.join}]*)\s*(?<term>.*)$/
end

Instance Method Details

#to_sql(field) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/card/query/value.rb', line 18

def to_sql field
  if @operator == "~"
    match_sql field
  else
    standard_sql field
  end
end