class ChambaSearchMx::Finder

finds jobs and returns simplified objects of them selfs

Attributes

jobs[R]

@attribute <Array>

Public Class Methods

new(options = {}) click to toggle source
# File lib/chamba_search_mx/finder.rb, line 8
def initialize(options = {})
  @formatter = options[:formatter] || ChambaSearchMx::UrlFormatter.new
  @pagination = options[:pagination] || ChambaSearchMx::Pagination.new
  @search_page = options[:search_page] || ChambaSearchMx::SearchPage.new
  @job = options[:job] || ChambaSearchMx::JobPage.new
end

Public Instance Methods

find(search, options = {}) click to toggle source

@param <String> search @param <Hash> options @return <Class> self

# File lib/chamba_search_mx/finder.rb, line 19
def find(search, options = {})
  @search = search
  @options = options
  validate_arguments
  find_jobs
  self
end

Private Instance Methods

find_jobs() click to toggle source

@return <Array>

# File lib/chamba_search_mx/finder.rb, line 46
def find_jobs
  @jobs = job_urls.map { |url| @job.load(url).data }
end
format_url() click to toggle source

@returm <string>

# File lib/chamba_search_mx/finder.rb, line 64
def format_url
  opts = search_options
  @formatter.format @search, opts
end
job_urls() click to toggle source

@return <Array>

# File lib/chamba_search_mx/finder.rb, line 52
def job_urls
  pagination_urls.map { |url| @search_page.load(url).job_urls }.flatten
end
pagination_urls() click to toggle source

@return <Array>

# File lib/chamba_search_mx/finder.rb, line 58
def pagination_urls
  @pagination.load(format_url).urls
end
search_options() click to toggle source

@return <Hash>

# File lib/chamba_search_mx/finder.rb, line 71
def search_options
  {
    location: @options[:location] || 'default',
    days: @options[:days] || 'default',
    salary: @options[:salary] || 'default'
  }
end
search_valid?() click to toggle source

@return <Boolean>

# File lib/chamba_search_mx/finder.rb, line 38
def search_valid?
  return false if @search.class != String
  return false if @search.empty?
  true
end
validate_arguments() click to toggle source

@raise <ArgumentError>

# File lib/chamba_search_mx/finder.rb, line 31
def validate_arguments
  error_msg = 'search must be a non empty string'
  raise ArgumentError, error_msg unless search_valid?
end