class SearchyJson::Query
Constants
- END_EXTRACT
- NEGATIVE
- START_EXTRACT
Attributes
text[R]
Public Class Methods
new(text)
click to toggle source
# File lib/searchy/query.rb, line 9 def initialize(text) @text = text end
Public Instance Methods
exact_matches?()
click to toggle source
# File lib/searchy/query.rb, line 21 def exact_matches? @exact_matches ||= !(text =~ START_EXTRACT && text =~ END_EXTRACT).nil? end
negative_keywords()
click to toggle source
# File lib/searchy/query.rb, line 13 def negative_keywords keywords_by_type[:negative] end
positive_keywords()
click to toggle source
# File lib/searchy/query.rb, line 17 def positive_keywords keywords_by_type[:positive] end
Private Instance Methods
exact_keywords_by_type()
click to toggle source
# File lib/searchy/query.rb, line 31 def exact_keywords_by_type negative = [] positive = [] keywords.each do |word| negative?(word) ? negative.push(word.gsub(NEGATIVE, '')) : positive.push(word) end { negative: negative, positive: positive } end
keywords()
click to toggle source
# File lib/searchy/query.rb, line 46 def keywords @keywords ||= text.gsub(START_EXTRACT, '').gsub(END_EXTRACT, '').upcase.split(' ') end
keywords_by_type()
click to toggle source
# File lib/searchy/query.rb, line 27 def keywords_by_type @keywords_by_type ||= exact_keywords_by_type end
negative?(keyword)
click to toggle source
# File lib/searchy/query.rb, line 42 def negative?(keyword) keyword =~ NEGATIVE end