Sha256: 87390c1b8b58ce2e1b8f8e78307e9b2b07e1bfd51832e73c8dcdbdf5f4955dd0

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

require 'rubygems'
require 'plist'

module Spotlight
  class Query
    attr_reader :query_string
    attr_accessor :scopes

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

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

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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spotlight-0.0.5 lib/spotlight/query.rb