1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
class Readme < String
attr_reader :path
def initialize(path)
@path = path
super(File.read(self.path))
end
def summary
if self =~ /^# (?:\S+)\s+(.+?)\s{2,}/m
scrub $1
else
raise "could not find summary in #{path}"
end
end
def description
if self =~ /^## Description\s+(.+?)\s{2,}/m
scrub $1
else
raise "could not find description in #{path}"
end
end
private
def scrub(string)
string.delete("\\`").gsub(/\[([^\]]+)\]\([^)]*\)/, "\\1").tr("\n", " ").to_s
end
end
class Files < Array
def executables
grep(%r{^bin/}) { |f| File.basename(f) }
end
def requires
["lib"]
end
def tests
grep(%r{^(test|spec|features)/})
end
end
def files
@files ||= Files.new(`find lib -name \*.rb`.split($/))
end
def readme(path = File.expand_path("./README.md"))
(@readmes ||= {})[path] ||= Readme.new(path)
end
|