Class: Gill::Parse
- Inherits:
-
Object
- Object
- Gill::Parse
- Defined in:
- lib/gill/parse.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#repo ⇒ Object
Returns the value of attribute repo.
Instance Method Summary collapse
-
#get_folder(repo) ⇒ String
Find the folder name from the repository uri.
-
#initialize(uri) ⇒ Parse
constructor
Initialize a ne wparse object.
-
#start ⇒ Object
Set and verefiy the category, folder and repository uri for the parsed object.
-
#valid?(repo) ⇒ String
Check to verify the passed uri is a valid repository uri.
Constructor Details
#initialize(uri) ⇒ Parse
Initialize a ne wparse object.
12 13 14 15 |
# File 'lib/gill/parse.rb', line 12 def initialize(uri) @uri = uri.split(/\#/) self.start end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
5 6 7 |
# File 'lib/gill/parse.rb', line 5 def category @category end |
#folder ⇒ Object
Returns the value of attribute folder.
5 6 7 |
# File 'lib/gill/parse.rb', line 5 def folder @folder end |
#repo ⇒ Object
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.
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 |
#start ⇒ Object
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.
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 |