Class: Gonzui::SearchQuery

Inherits:
Object
  • Object
show all
Includes:
Enumerable, GetText
Defined in:
lib/gonzui/searchquery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetText

#gettext, #gettext_noop, #load_catalog, #set_catalog

Constructor Details

#initialize(config, query_string, options = {}) ⇒ SearchQuery

Returns a new instance of SearchQuery.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gonzui/searchquery.rb', line 35

def initialize(config, query_string, options = {})
  @query_string = query_string
  @options = options
  @items = []

  @package = nil
  @path = nil
  @format = nil
  @license = nil
  @error = nil

  @words = []
  @ignored_words = []

  @max_words = config.max_words
  @nwords = 0
  parse_query_string
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



55
56
57
# File 'lib/gonzui/searchquery.rb', line 55

def format
  @format
end

#ignored_wordsObject (readonly)

Returns the value of attribute ignored_words.



57
58
59
# File 'lib/gonzui/searchquery.rb', line 57

def ignored_words
  @ignored_words
end

#licenseObject (readonly)

Returns the value of attribute license.



56
57
58
# File 'lib/gonzui/searchquery.rb', line 56

def license
  @license
end

#optionsObject (readonly)

Returns the value of attribute options.



59
60
61
# File 'lib/gonzui/searchquery.rb', line 59

def options
  @options
end

#packageObject (readonly)

Returns the value of attribute package.



54
55
56
# File 'lib/gonzui/searchquery.rb', line 54

def package
  @package
end

#pathObject

Returns the value of attribute path.



53
54
55
# File 'lib/gonzui/searchquery.rb', line 53

def path
  @path
end

#wordsObject (readonly)

Returns the value of attribute words.



58
59
60
# File 'lib/gonzui/searchquery.rb', line 58

def words
  @words
end

Instance Method Details

#collectObject



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gonzui/searchquery.rb', line 193

def collect
  @items.find_all {|item| 
    if block_given?
      yield(item)
    else
      true
    end
  }.map {|item| 
    item.value
  }
end

#eachObject



185
186
187
# File 'lib/gonzui/searchquery.rb', line 185

def each
  @items.each {|item| yield(item) }
end

#empty?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/gonzui/searchquery.rb', line 173

def empty?
  @items.empty? and @package.nil? and @path.nil?
end

#firstObject



177
178
179
# File 'lib/gonzui/searchquery.rb', line 177

def first
  @items.first
end

#keywordsObject



205
206
207
# File 'lib/gonzui/searchquery.rb', line 205

def keywords
  collect {|item| not item.phrase? }
end

#lastObject



181
182
183
# File 'lib/gonzui/searchquery.rb', line 181

def last
  @items.last
end

#lengthObject



189
190
191
# File 'lib/gonzui/searchquery.rb', line 189

def length
  @items.length
end

#package_only?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/gonzui/searchquery.rb', line 157

def package_only?
  @items.empty? and @path.nil? and @package
end

#path_only?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/gonzui/searchquery.rb', line 153

def path_only?
  @items.empty? and @path and @package.nil?
end

#phrasesObject



209
210
211
# File 'lib/gonzui/searchquery.rb', line 209

def phrases
  collect {|item| item.phrase? }
end

#simplified_stringObject



165
166
167
# File 'lib/gonzui/searchquery.rb', line 165

def simplified_string
  @items.map {|item| item.to_s }.join(" ")
end

#stringObject



161
162
163
# File 'lib/gonzui/searchquery.rb', line 161

def string
  @query_string
end

#string_without_propertiesObject



169
170
171
# File 'lib/gonzui/searchquery.rb', line 169

def string_without_properties
  @items.map {|item| item.value.to_s }.join(" ")
end

#tokenize_allObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/gonzui/searchquery.rb', line 213

def tokenize_all
  original_items = @items.clone
  original_nwords = @nwords
  reset
  original_items.each {|item|
    if item.phrase?
      value = item.value.join(" ")
      add_item_for_phrase(item.property, value)
    else
      add_item_for_phrase(item.property, item.value)
    end
  }
  make_words

  modified = if @nwords != original_nwords then true else false end
  return modified
end

#validateObject

Raises:

  • (@error)


231
232
233
# File 'lib/gonzui/searchquery.rb', line 231

def validate
  raise @error if @error
end