class JobGrabber::Controller
Constants
- DEFAULT_FORMAT
- DEFAULT_NUMBER
- DEFAULT_SOURCES
Attributes
jobs[R]
Public Class Methods
new(sources = DEFAULT_SOURCES, format = DEFAULT_FORMAT, number = DEFAULT_NUMBER)
click to toggle source
# File lib/controller.rb, line 15 def initialize(sources = DEFAULT_SOURCES, format = DEFAULT_FORMAT, number = DEFAULT_NUMBER) @sources = sources @format = format @jobs = Array.new @formatted_jobs = Array.new @number = number @jobs = JobGrabber::Base.new(@sources).grab end
Public Instance Methods
add_source(source)
click to toggle source
# File lib/controller.rb, line 23 def add_source source @sources.push(source) @jobs = JobGrabber::Base.new(@sources).grab end
get_by_category(category)
click to toggle source
# File lib/controller.rb, line 60 def get_by_category category category = category.downcase @jobs.select{|job| job.description.downcase.include?category}.sort{|a,b|a.created_at<=>a.created_at}.map{|job| job.format(@format)}[0...@number] end
get_by_source(source)
click to toggle source
# File lib/controller.rb, line 54 def get_by_source source if !@sources.include?source raise "Source unknown, add it to the source list first" end @jobs.select{|job| job.origin == source}.sort{|a,b|a.created_at<=>a.created_at}.map{|job| job.format(@format)} end
get_job(id)
click to toggle source
# File lib/controller.rb, line 51 def get_job id @jobs.detect{|job| job.id == id}.format(@format) end
get_job_count()
click to toggle source
# File lib/controller.rb, line 42 def get_job_count @jobs.count end
get_jobs_formatted()
click to toggle source
# File lib/controller.rb, line 48 def get_jobs_formatted @jobs.sort{|a,b|b.created_at<=>a.created_at}.map{|job| job.format(@format)}[0...@number] end
get_jobs_from_date(date)
click to toggle source
# File lib/controller.rb, line 45 def get_jobs_from_date date @jobs.select{|job| DateTime.parse(job.created_at) > date}.sort{|a,b|a.created_at<=>a.created_at}.map{|job| job.format(@format)}[0...@number] end
get_sources(with_count = false)
click to toggle source
# File lib/controller.rb, line 34 def get_sources with_count = false unless with_count @sources end end
remove_source(source)
click to toggle source
# File lib/controller.rb, line 27 def remove_source source @sources.select!{|src| !src.include?source} @jobs.select!{|job| !job.origin.include?source} end
set_format(format)
click to toggle source
# File lib/controller.rb, line 39 def set_format format @format = format end
set_number(number)
click to toggle source
# File lib/controller.rb, line 31 def set_number number @number = Integer(number) end