Class: URLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/url_parser.rb

Class Method Summary collapse

Class Method Details

.parse(content) ⇒ Object



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
# File 'lib/url_parser.rb', line 2

def URLParser.parse content
  urls = {git: [], svn: [], hg: []}
  repo_state = :git

  content.split("\n").each do |line|
    # change the repo state
    # all urls following this will be labeled with this state
    if line.match /^#~(git|svn|hg)/
	repo_state = $1.to_sym 
	next
    end

    # skip comments
    next if line.match /^#/

    # skip empty lines
    next if line.match /^\s*$/

    # everything else is considered a url
    # remove whitespace before and after the string to clean it up
    urls[repo_state] << line.strip
  end

  urls
end