23 Ağustos 2007 Perşembe

Full text searching for ri content

Author: zenspider, http://blog.zenspider.com/archives/2006/08/full_text_searc.html


#From ZenSpider, http://blog.zenspider.com/archives/2006/08/full_text_searc.html:
#Check it out. Quick and dirty searching of ri content:
#Updated using: http://blog.zenspider.com/archives/2006/08/new_and_improve.html
# They added path independence and searching of gems and local installed ri/rdoc. Enjoy!#!/usr/local/bin/ruby -w

require 'rdoc/ri/ri_paths'
require 'find'
require 'yaml'
search = ARGV.shift
puts "Searching for #{search}"
puts
dirs = RI::Paths::PATH
dirs.each do dir
Dir.chdir dir do
Find.find('.') do path
next unless test ?f, path
yaml = File.read path
if yaml =~ /#{search}/io then
full_name = $1 if yaml[/full_name: (.*)/]
puts "** FOUND IN: #{full_name}"
data = YAML.load yaml.gsub(/ \!.*/, '')
desc = data['comment'].map { x x.values }.flatten.join("\n").gsub(/&quot;/, "'").gsub(/&lt;/, "<").gsub(/&gt;/, ">").gsub(/&amp;/, "&")
puts
puts desc
puts
end
end
end
end

# Lets you do stuff like:
% ./risearch.rb duplicate
# Searching for duplicate

[...]

** FOUND IN: Array#uniq!
# Removes duplicate elements from self. Returns nil if no changes are made (that is, no duplicates are found).
a = [ 'a', 'a', 'b', 'b', 'c' ]
a.uniq! #=> ['a', 'b', 'c']
b = [ 'a', 'b', 'c' ]
b.uniq! #=> nil
** FOUND IN: Array#
# Set Union---Returns a new array by joining this array with other_array, removing duplicates.
[ 'a', 'b', 'c' ] [ 'c', 'd', 'a' ]
#=> [ 'a', 'b', 'c', 'd' ]
[...]


0 Comments: