Module: RJack::TarPit::ReadmeParser

Defined in:
lib/rjack-tarpit/readme_parser.rb

Overview

Helper mixin for deriving default spec properties from the README (rdoc,txt) file

Instance Method Summary collapse

Instance Method Details

#parse_readme(file) ⇒ Object

Parse the given README file, setting properties homepage, summary, and description on self if possible.



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
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rjack-tarpit/readme_parser.rb', line 27

def parse_readme( file )

  in_desc = false
  desc = ""

  readme_file_open( file ) do |fin|
    fin.each do |line|
      if homepage.nil? && line =~ /^\s*\*\s*(http\S+)\s*$/
        self.homepage = $1
      elsif line =~ /^=/ # section header
        in_desc = ( line =~ /^=+\s*Description\s*$/i )
        # Stop at new section if we already have a description
        break unless desc.empty?
      elsif in_desc
        # Stop if empty line after description, or bullet (*) list
        break if ( !desc.empty? && line =~ /^\s*$/ ) || line =~ /^\s*\*/
        desc << line
      end
    end
  end

  desc = desc.
    gsub( /\s+/, ' ' ). #Simplify whitespace
    gsub( /\{([^\}]+)\}\[[^\]]*\]/, '\1' ). # Replace rdoc link \w anchor
    gsub( /(\S)\[\s*http:[^\]]*\]/, '\1' ). # Replace bare rdoc links
    strip.
    sub( /:$/, '.' ) # Replace a final ':', like when term. at list

  # Summary is first sentence if we find one, or entire desc otherwise
  if desc =~ /^(.+[!?:.])\s/
    self.summary = $1.strip
    self.description = desc # Use remainder for description
  else
    self.summary = desc
  end

end