Class: Spotlight::Query
- Inherits:
-
Object
- Object
- Spotlight::Query
- Defined in:
- lib/spotlight/query.rb
Instance Attribute Summary collapse
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(query_string) ⇒ Query
constructor
A new instance of Query.
- #to_saved_search(filename) ⇒ Object
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_string ⇒ Object (readonly)
Returns the value of attribute query_string.
6 7 8 |
# File 'lib/spotlight/query.rb', line 6 def query_string @query_string end |
#scopes ⇒ Object
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
#execute ⇒ Object
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 |