Class: Gill::Parse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Parse

Initialize a ne wparse object.

Parameters:

  • uri (String)

    The string to be parsed and retunred to create a gill cloned repository.



12
13
14
15
# File 'lib/gill/parse.rb', line 12

def initialize(uri)
  @uri = uri.split(/\#/)
  self.start
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



5
6
7
# File 'lib/gill/parse.rb', line 5

def category
  @category
end

#folderObject

Returns the value of attribute folder.



5
6
7
# File 'lib/gill/parse.rb', line 5

def folder
  @folder
end

#repoObject

Returns the value of attribute repo.



5
6
7
# File 'lib/gill/parse.rb', line 5

def repo
  @repo
end

Instance Method Details

#get_folder(repo) ⇒ String

Find the folder name from the repository uri.

Parameters:

  • repo (String)

    The uri for the remote repository.

Returns:

  • (String)

    repo The folder/project name of the passed uri.



84
85
86
87
88
89
90
91
92
93
# File 'lib/gill/parse.rb', line 84

def get_folder(repo)
  
  if repo =~ /\.git/i
    repo_name = repo.match(/\S+[\/|\:](\S+)\.git/i)[1]
  else
    repo_name = repo.match(/\S+[\/|\:](\S+)\Z/i)[1]
  end
  
  repo_name
end

#startObject

Set and verefiy the category, folder and repository uri for the parsed object.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gill/parse.rb', line 47

def start
  self.category = @uri.first
  
  if @uri.length == 3
    
    self.repo = @uri.first if valid?(@uri.first)
    self.category = @uri[1]
    self.folder = @uri.last      
    
  elsif @uri.length == 2
    
    self.category = @uri.last
    self.repo = @uri.first if valid?(@uri.first)
    self.folder = get_folder(self.repo)
    
  elsif @uri.length < 2
    
    self.category = false
    self.repo = @uri.first if valid?(@uri.first)
    self.folder = get_folder(self.repo)
    
  else
    
    raise(ArgumentError, "too many arguments.")
    
  end
end

#valid?(repo) ⇒ String

Check to verify the passed uri is a valid repository uri.

Parameters:

  • repo (String)

    The uri to the remote repository.

Returns:

  • (String)

    repo Return the repository uri if it is indeed a valid uri.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gill/parse.rb', line 104

def valid?(repo)
  case repo
    when repo[/\A(http|https|git)\:\/\/\S+[\:|\/]\S+[\.git|\Z]\Z/i]
      return repo
    when repo[/http\:\/\/\S+\Z|https\:\/\/\S+\Z|git\:\/\/\S+\Z/i]
      return repo
    when repo[/\A(\S+\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b\:\S+\S+[\.git|\Z])\Z/i]
      return repo
    when repo[/\A\S+\@\S+[\:|\/]\S+[\.git|\Z]\Z/i]
      return repo
    else
      raise(RepositoryError, 'not a git repository.')
  end
end