Module: Texticle::Helper

Defined in:
lib/texticle.rb

Class Method Summary collapse

Class Method Details

.dynamic_search_method?(method, class_columns) ⇒ Boolean

Returns:

  • (Boolean)


220
221
222
223
# File 'lib/texticle.rb', line 220

def dynamic_search_method?(method, class_columns)
  exclusive_dynamic_search_method?(method, class_columns) or
    inclusive_dynamic_search_method?(method, class_columns)
end

.exclusive_dynamic_search_columns(method) ⇒ Object



184
185
186
187
188
189
190
# File 'lib/texticle.rb', line 184

def exclusive_dynamic_search_columns(method)
  if match = method.to_s.match(method_name_regex)
    match[:columns].split('_and_')
  else
    []
  end
end

.exclusive_dynamic_search_method?(method, class_columns) ⇒ Boolean

Returns:

  • (Boolean)


200
201
202
203
204
205
206
207
208
# File 'lib/texticle.rb', line 200

def exclusive_dynamic_search_method?(method, class_columns)
  string_columns = class_columns.map(&:name)
  columns = exclusive_dynamic_search_columns(method)
  unless columns.empty?
    columns.all? {|column| string_columns.include?(column) }
  else
    false
  end
end

.inclusive_dynamic_search_columns(method) ⇒ Object



192
193
194
195
196
197
198
# File 'lib/texticle.rb', line 192

def inclusive_dynamic_search_columns(method)
  if match = method.to_s.match(method_name_regex)
    match[:columns].split('_or_')
  else
    []
  end
end

.inclusive_dynamic_search_method?(method, class_columns) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
213
214
215
216
217
218
# File 'lib/texticle.rb', line 210

def inclusive_dynamic_search_method?(method, class_columns)
  string_columns = class_columns.map(&:name)
  columns = inclusive_dynamic_search_columns(method)
  unless columns.empty?
    columns.all? {|column| string_columns.include?(column) }
  else
    false
  end
end

.method_name_regexObject



176
177
178
# File 'lib/texticle.rb', line 176

def method_name_regex
  /^(?<search_type>((basic|advanced|fuzzy)_)?search)_by_(?<columns>[_a-zA-Z]\w*)$/
end

.normalize(query) ⇒ Object



172
173
174
# File 'lib/texticle.rb', line 172

def normalize(query)
  query.to_s.gsub(' ', '\\\\ ')
end

.search_type(method) ⇒ Object



180
181
182
# File 'lib/texticle.rb', line 180

def search_type(method)
  method.to_s.match(method_name_regex)[:search_type]
end