Class: Sogger::Runner
- Inherits:
-
Object
- Object
- Sogger::Runner
- Defined in:
- lib/sogger/runner.rb
Class Attribute Summary collapse
-
.growl_interval ⇒ Object
Returns the value of attribute growl_interval.
-
.logging ⇒ Object
Returns the value of attribute logging.
-
.update_interval ⇒ Object
Returns the value of attribute update_interval.
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
- #growl(question) ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #log(text) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sogger/runner.rb', line 13 def initialize( = {}) [:update_interval] ||= Runner.update_interval [:growl_interval] ||= Runner.growl_interval [:logging] = [:logging].nil? ? Runner.logging : [:logging] Runner.update_interval = [:update_interval] Runner.growl_interval = [:growl_interval] Runner.logging = [:logging] @filter = [*[:filter]].compact @cached_sogger = Sogger.new @remote_sogger = Sogger.new @questions_buffer = [] @growler = Meow.new("Sogger") end |
Class Attribute Details
.growl_interval ⇒ Object
Returns the value of attribute growl_interval.
4 5 6 |
# File 'lib/sogger/runner.rb', line 4 def growl_interval @growl_interval end |
.logging ⇒ Object
Returns the value of attribute logging.
4 5 6 |
# File 'lib/sogger/runner.rb', line 4 def logging @logging end |
.update_interval ⇒ Object
Returns the value of attribute update_interval.
4 5 6 |
# File 'lib/sogger/runner.rb', line 4 def update_interval @update_interval end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
7 8 9 |
# File 'lib/sogger/runner.rb', line 7 def filter @filter end |
Instance Method Details
#growl(question) ⇒ Object
82 83 84 85 86 |
# File 'lib/sogger/runner.rb', line 82 def growl(question) @growler.notify(question..join(', '), question.title) do system "open", question.url end end |
#log(text) ⇒ Object
88 89 90 |
# File 'lib/sogger/runner.rb', line 88 def log(text) puts text if Runner.logging end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sogger/runner.rb', line 29 def run updater = Thread.new("updater") do while true log "Updater: Downloading feed..." @remote_sogger.download_feed! new_questions = [] unless @cached_sogger.questions.empty? log "Updater: Comparing feeds..." new_questions = (@remote_sogger - @cached_sogger).questions end unless new_questions.empty? log "Updater: Adding #{new_questions.size} questions to buffer..." @questions_buffer += new_questions end log "Updater: Caching feed..." @remote_sogger.save! log "Updater: Loading cached feed..." @cached_sogger.load! log "Updater: Sleeping for #{Runner.update_interval} seconds..." sleep Runner.update_interval end end notifier = Thread.new("notifier") do while true unless @questions_buffer.empty? log "\nNotifier: Filtering questions..." while question = @questions_buffer.pop if @filter.empty? || question..any?{ |t| @filter.include?(t) } log "\nNotifier: Growling..." growl(question) break end end end sleep Runner.growl_interval end end trap("INT") do puts " Exiting, please wait..." [updater, notifier].map(&:kill) end [updater, notifier].map(&:join) end |