Class: Gonzui::SearchQuery
- Inherits:
-
Object
- Object
- Gonzui::SearchQuery
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
Returns the value of attribute format.
55
56
57
|
# File 'lib/gonzui/searchquery.rb', line 55
def format
@format
end
|
#ignored_words ⇒ Object
Returns the value of attribute ignored_words.
57
58
59
|
# File 'lib/gonzui/searchquery.rb', line 57
def ignored_words
@ignored_words
end
|
#license ⇒ Object
Returns the value of attribute license.
56
57
58
|
# File 'lib/gonzui/searchquery.rb', line 56
def license
@license
end
|
#options ⇒ Object
Returns the value of attribute options.
59
60
61
|
# File 'lib/gonzui/searchquery.rb', line 59
def options
@options
end
|
#package ⇒ Object
Returns the value of attribute package.
54
55
56
|
# File 'lib/gonzui/searchquery.rb', line 54
def package
@package
end
|
#path ⇒ Object
Returns the value of attribute path.
53
54
55
|
# File 'lib/gonzui/searchquery.rb', line 53
def path
@path
end
|
#words ⇒ Object
Returns the value of attribute words.
58
59
60
|
# File 'lib/gonzui/searchquery.rb', line 58
def words
@words
end
|
Instance Method Details
#collect ⇒ Object
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
|
#each ⇒ Object
185
186
187
|
# File 'lib/gonzui/searchquery.rb', line 185
def each
@items.each {|item| yield(item) }
end
|
#empty? ⇒ Boolean
173
174
175
|
# File 'lib/gonzui/searchquery.rb', line 173
def empty?
@items.empty? and @package.nil? and @path.nil?
end
|
#first ⇒ Object
177
178
179
|
# File 'lib/gonzui/searchquery.rb', line 177
def first
@items.first
end
|
#keywords ⇒ Object
205
206
207
|
# File 'lib/gonzui/searchquery.rb', line 205
def keywords
collect {|item| not item.phrase? }
end
|
#last ⇒ Object
181
182
183
|
# File 'lib/gonzui/searchquery.rb', line 181
def last
@items.last
end
|
#length ⇒ Object
189
190
191
|
# File 'lib/gonzui/searchquery.rb', line 189
def length
@items.length
end
|
#package_only? ⇒ 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
153
154
155
|
# File 'lib/gonzui/searchquery.rb', line 153
def path_only?
@items.empty? and @path and @package.nil?
end
|
#phrases ⇒ Object
209
210
211
|
# File 'lib/gonzui/searchquery.rb', line 209
def phrases
collect {|item| item.phrase? }
end
|
#simplified_string ⇒ Object
165
166
167
|
# File 'lib/gonzui/searchquery.rb', line 165
def simplified_string
@items.map {|item| item.to_s }.join(" ")
end
|
#string ⇒ Object
161
162
163
|
# File 'lib/gonzui/searchquery.rb', line 161
def string
@query_string
end
|
#string_without_properties ⇒ Object
169
170
171
|
# File 'lib/gonzui/searchquery.rb', line 169
def string_without_properties
@items.map {|item| item.value.to_s }.join(" ")
end
|
#tokenize_all ⇒ Object
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
|
#validate ⇒ Object
231
232
233
|
# File 'lib/gonzui/searchquery.rb', line 231
def validate
raise @error if @error
end
|