Class: Fargo::Search

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#filetypeObject

Returns the value of attribute filetype.



12
13
14
# File 'lib/fargo/search.rb', line 12

def filetype
  @filetype
end

#is_minimum_sizeObject

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

#patternObject

Returns the value of attribute pattern.



12
13
14
# File 'lib/fargo/search.rb', line 12

def pattern
  @pattern
end

#sizeObject

Returns the value of attribute size.



12
13
14
# File 'lib/fargo/search.rb', line 12

def size
  @size
end

#size_restrictedObject

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

Returns:

  • (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

#queriesObject



31
32
33
# File 'lib/fargo/search.rb', line 31

def queries
  pattern.split('$')
end

#queryObject



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_sObject



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