Sha256: f7c3b88691f5048c073d2c6a577d50c938299d31668352b14dfca71d714de5f9

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

require 'open-uri'
require 'Hpricot'

require 'craigler/constants'
require 'craigler/search'

module Craigler
  class CraiglerError < StandardError; end
  class InvalidCategory < CraiglerError; end
  class InvalidSearchTerm < CraiglerError; end
  class InvalidLocation < CraiglerError; end
  
  class << self
    # Interface to Search that may or may not be more readable
    def search(category, options = {})
      results = Search.new(options[:for], :in => (options[:in] || :anywhere), :only => category).results()
      results.each {|result| yield(result) } if block_given?
      results
    end
    
    # Interface to Search that somewhat mimics ActiveRecord#find
    #
    # Supports all the options of Search#new
    def find(search_term, options = {})
      results = Search.new(search_term, options).results()
      results.each {|result| yield(result) } if block_given?
      results
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quixoten-craigler-1.1.0 lib/craigler.rb