Class: Fargo::Search
- Inherits:
-
Object
- Object
- Fargo::Search
- Defined in:
- lib/fargo/search.rb
Constant Summary collapse
- ANY =
1
- AUDIO =
2
- COMPRESSED =
3
- DOCUMENT =
4
- EXECUTABLE =
5
- VIDEO =
7
- FOLDER =
8
Instance Attribute Summary collapse
-
#filetype ⇒ Object
Returns the value of attribute filetype.
-
#is_minimum_size ⇒ Object
Returns the value of attribute is_minimum_size.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#size ⇒ Object
Returns the value of attribute size.
-
#size_restricted ⇒ Object
Returns the value of attribute size_restricted.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Search
constructor
A new instance of Search.
- #matches_result?(map) ⇒ Boolean
- #queries ⇒ Object
- #query ⇒ Object
- #query=(query) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Search
Returns a new instance of Search.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fargo/search.rb', line 14 def initialize opts = {} @size_restricted = opts[:size_restricted] @is_minimum_size = opts[:is_minimum_size] @size = opts[:size] @filetype = opts[:filetype] || ANY if opts[:pattern] @pattern = opts[:pattern] elsif opts[:query] self.query = opts[:query] end end |
Instance Attribute Details
#filetype ⇒ Object
Returns the value of attribute filetype.
12 13 14 |
# File 'lib/fargo/search.rb', line 12 def filetype @filetype end |
#is_minimum_size ⇒ Object
Returns the value of attribute is_minimum_size.
12 13 14 |
# File 'lib/fargo/search.rb', line 12 def is_minimum_size @is_minimum_size end |
#pattern ⇒ Object
Returns the value of attribute pattern.
12 13 14 |
# File 'lib/fargo/search.rb', line 12 def pattern @pattern end |
#size ⇒ Object
Returns the value of attribute size.
12 13 14 |
# File 'lib/fargo/search.rb', line 12 def size @size end |
#size_restricted ⇒ Object
Returns the value of attribute size_restricted.
12 13 14 |
# File 'lib/fargo/search.rb', line 12 def size_restricted @size_restricted end |
Instance Method Details
#matches_result?(map) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fargo/search.rb', line 39 def matches_result? map file = map[:file].downcase matches_query = queries.inject(true) do |last, word| last && file.index(word.downcase) end if size_restricted == 'T' if is_minimum_size matches_query && map[:size] > size else matches_query && map[:size] < size end else matches_query end end |
#queries ⇒ Object
31 32 33 |
# File 'lib/fargo/search.rb', line 31 def queries pattern.split('$') end |
#query ⇒ Object
35 36 37 |
# File 'lib/fargo/search.rb', line 35 def query pattern.gsub('$', ' ') end |
#query=(query) ⇒ Object
27 28 29 |
# File 'lib/fargo/search.rb', line 27 def query= query @pattern = query.split(' ').join('$') end |
#to_s ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/fargo/search.rb', line 57 def to_s if size_restricted "#{size_restricted ? 'T' : 'F' }?#{!size_restricted || is_minimum_size ? 'T' : 'F'}?#{size || 0}?#{filetype}?#{pattern}" else "F?T?#{size || 0}?#{filetype}?#{pattern}" end end |