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 |
# File 'lib/fargo/search.rb', line 14 def initialize opts = {} self.size_restricted = opts[:size_restricted] self.is_minimum_size = opts[:is_minimum_size] self.size = opts[:size] self.filetype = opts[:filetype] || ANY if opts[:pattern] self.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
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fargo/search.rb', line 38 def matches_result? map file = map[:file].downcase matches_query = queries.inject(true) { |last, word| last && file.index(word.downcase) } 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
30 31 32 |
# File 'lib/fargo/search.rb', line 30 def queries pattern.split("$") end |
#query ⇒ Object
34 35 36 |
# File 'lib/fargo/search.rb', line 34 def query pattern.gsub('$', ' ') end |
#query=(query) ⇒ Object
26 27 28 |
# File 'lib/fargo/search.rb', line 26 def query= query @pattern = query.split(' ').join('$') end |
#to_s ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/fargo/search.rb', line 52 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 |