Class: AlleJest::Runner
Overview
That’s awfully, procedurally designed, but I don’t care. It should just do it’s job.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #read_config(path) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
234 235 236 |
# File 'lib/allejest.rb', line 234 def initialize( = {}) read_config([:config_path]) if .has_key? :config_path end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
232 233 234 |
# File 'lib/allejest.rb', line 232 def config @config end |
Class Method Details
Instance Method Details
#read_config(path) ⇒ Object
238 239 240 241 242 243 244 |
# File 'lib/allejest.rb', line 238 def read_config(path) return nil if path.blank? content = File.read(path) self.config = YAML.load(content) config.deep_symbolize_keys! if config.is_a? Hash end |
#run ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/allejest.rb', line 246 def run reader = Reader.new(config[:reader]) # TODO move to Reader feeds = reader.map_feeds_to_queries results = feeds.map do |query, feed| result = SearchResult.new(:query => query, :feed => feed) result.items = feed.entries.map do |entry| Item.new(:feed_entry => entry) end result end # Filter results not matching the query results.each { |r| r.items = [] if !r.matches_query? } # EOT (end of TODO) if config[:general].try(:[], :filter) == true # (expr == 0) in Ruby evaluates to true! filter = Filter.new(:filter_db_path => File.join(File.("~"), ".allejest", 'filter_db.yml')) results = filter.filter(results) filter.close end # A singleton method :-) I always wanted to write one def results.blank? return true if self.length == 0 self.all? do |r| r.items.blank? end end # E-mail only if there are results unless results.blank? emailer_config = config[:emailer].slice(:from_address, :smtp) send_to = config[:emailer][:send_to][0].slice(:email, :firstname, :lastname) emailer = Emailer.new(emailer_config.merge!(send_to).merge!({:results => results})) emailer.send_mail end end |