Class: Spotlight::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/spotlight/query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_string) ⇒ Query

Returns a new instance of Query.



16
17
18
19
# File 'lib/spotlight/query.rb', line 16

def initialize(query_string)
  @query_string = query_string
  @scopes = []
end

Instance Attribute Details

#query_stringObject (readonly)

Returns the value of attribute query_string.



6
7
8
# File 'lib/spotlight/query.rb', line 6

def query_string
  @query_string
end

#scopesObject

Returns the value of attribute scopes.



7
8
9
# File 'lib/spotlight/query.rb', line 7

def scopes
  @scopes
end

Class Method Details

.from_saved_search(filename) ⇒ Object



9
10
11
12
13
14
# File 'lib/spotlight/query.rb', line 9

def self.from_saved_search(filename)
  plist = Plist::parse_xml(filename)
  query = new(plist['RawQuery'])
  query.scopes = plist['SearchCriteria']['FXScopeArrayOfPaths']
  query
end

Instance Method Details

#executeObject



21
22
23
24
25
# File 'lib/spotlight/query.rb', line 21

def execute
  md_query = MDQueryNative.new(query_string)
  md_query.set_search_scopes(scopes)
  md_query.execute
end

#to_saved_search(filename) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spotlight/query.rb', line 27

def to_saved_search(filename)
  obj = {
    'RawQuery' => query_string,
    'SearchCriteria' => {
      'FXScopeArrayOfPaths' => scopes
    }
  }

  File.open(filename, 'w') do |file|
    file.write(obj.to_plist)
  end
end