Method: LinuxFortune.search

Defined in:
lib/linux_fortune.rb

.search(pattern = nil, sources = nil) ⇒ Object

searches fortune sources and returns hits pattern - search pattern (grep-like) sources - array of sources to be searched (all if not specified)



199
200
201
202
203
204
205
206
207
# File 'lib/linux_fortune.rb', line 199

def self.search(pattern = nil, sources = nil)
  # reset long / short filters
  LinuxFortune.long = false
  LinuxFortune.short = false
  # run fortune
  results = `#{self.binary_path} -c -m "#{pattern.gsub(/"/, '\\"')}" #{fortune_options} #{sources.each { |source| source.to_s }.join(" ") unless sources.nil?} 2>&1`
  # process results
  LinuxFortune::Fortune.fortunes(results)
end