repo_parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/Rakefile +7 -0
- data/bin/repo-parser +6 -0
- data/lib/repo_parser.rb +82 -0
- data/lib/repo_parser/version.rb +3 -0
- data/repo_parser.gemspec +26 -0
- data/spec/repo_parser_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1180f8516b67a9b21081e92d6d95b74fd61cf4f0
|
4
|
+
data.tar.gz: b2f0122d9def6afbf34c078f819cb9d4c69db4d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75d8cb3d02ae2a4b5e0b2f5991c7173fcedb2d990491e0ee2a2d21de5b4e600cd6e3ca273fe3cdcf22fb545b3f019d8c39b5599e8b65cc7953933ee3d534af5b
|
7
|
+
data.tar.gz: c97338b7cbfc8642f2a442865f6f5c7cbfbe88053802af3f1674c3049d353acae50e0fc8e258aa67bee469d244ac94b6eef80cf011e679a10982ed9805e1c63c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Matthew Rudy Jacobs
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# RepoParser
|
2
|
+
|
3
|
+
A coding example.
|
4
|
+
|
5
|
+
## Task
|
6
|
+
|
7
|
+
Take response of https://api.github.com/repositories and perform the following actions;
|
8
|
+
|
9
|
+
* search results for any repository with “ruby” in the name and are not forks
|
10
|
+
* sort Alphabetically by owner name
|
11
|
+
* response should be displayed showing repo name, owner name, URL to repo
|
data/Rakefile
ADDED
data/bin/repo-parser
ADDED
data/lib/repo_parser.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'repo_parser/version'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
# RepoParser is a coding test
|
5
|
+
# involving scraping some github json,
|
6
|
+
# and sorting it.
|
7
|
+
module RepoParser
|
8
|
+
def self.run
|
9
|
+
repos = Parser.call(Fetcher.call)
|
10
|
+
sorted = Sorter.call(Filterer.call(repos))
|
11
|
+
Result.new(sorted)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Result < Struct.new(:repositories)
|
15
|
+
def to_string
|
16
|
+
lines = []
|
17
|
+
|
18
|
+
lines << <<-STRING
|
19
|
+
RepoParser
|
20
|
+
==========
|
21
|
+
STRING
|
22
|
+
|
23
|
+
repositories.each do |repo|
|
24
|
+
lines << <<-STRING
|
25
|
+
#{repo.name}:
|
26
|
+
name: #{repo.name}
|
27
|
+
url: #{repo.url}
|
28
|
+
owner: #{repo.owner}
|
29
|
+
STRING
|
30
|
+
end
|
31
|
+
|
32
|
+
lines << <<-STRING
|
33
|
+
Total: #{repositories.length}
|
34
|
+
STRING
|
35
|
+
|
36
|
+
lines.join('-' * 32 + "\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Fetcher fetches an api response
|
41
|
+
class Fetcher
|
42
|
+
def self.call
|
43
|
+
HTTParty.get('https://api.github.com/repositories').parsed_response
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Parser parses an api response into Repository objects
|
48
|
+
class Parser
|
49
|
+
def self.call(response)
|
50
|
+
response.map do |json|
|
51
|
+
Repository.new(json['name'],
|
52
|
+
json['html_url'],
|
53
|
+
json['owner']['login'],
|
54
|
+
json['fork'])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Repository represents a repository
|
60
|
+
Repository = Struct.new(:name, :url, :owner, :fork)
|
61
|
+
|
62
|
+
# Filterer filters non-matching repositories
|
63
|
+
class Filterer
|
64
|
+
def self.call(repos)
|
65
|
+
repos.select do |repo|
|
66
|
+
allow?(repo)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.allow?(repo)
|
71
|
+
repo.name =~ /ruby/ &&
|
72
|
+
!repo.fork
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Sorter sorts repos by owner
|
77
|
+
class Sorter
|
78
|
+
def self.call(repos)
|
79
|
+
repos.sort_by(&:owner)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/repo_parser.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'repo_parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'repo_parser'
|
8
|
+
spec.version = RepoParser::VERSION
|
9
|
+
spec.authors = ['Matthew Rudy Jacobs']
|
10
|
+
spec.email = ['matthewrudyjacobs@gmail.com']
|
11
|
+
spec.summary = 'RepoParser is a code example'
|
12
|
+
spec.description = 'Take the github repositories list, and filter it to ruby libraries.'
|
13
|
+
spec.homepage = 'https://github.com/matthewrudy/repo_parser'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'httparty', '~> 0.13.3'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RepoParser do
|
4
|
+
it 'returns a list of repositories' do
|
5
|
+
repositories = RepoParser.run.repositories
|
6
|
+
expect(repositories).to be_an(Array)
|
7
|
+
|
8
|
+
repo = repositories.first
|
9
|
+
expect(repo.name).to be_present
|
10
|
+
expect(repo.owner).to be_present
|
11
|
+
expect(repo.url).to be_present
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns the repositories ordered by owner' do
|
15
|
+
repositories = RepoParser.run.repositories
|
16
|
+
|
17
|
+
names = repositories.map(&:owner)
|
18
|
+
expect(names).to eq names.sort
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns only ruby repositories' do
|
22
|
+
repositories = RepoParser.run.repositories
|
23
|
+
|
24
|
+
names = repositories.map(&:name)
|
25
|
+
ruby_names = names.select do |name|
|
26
|
+
name =~ /ruby/i
|
27
|
+
end
|
28
|
+
|
29
|
+
expect(ruby_names).to eq names
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'repo_parser'
|
3
|
+
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.disable_monkey_patching!
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec::Matchers.define :be_present do
|
9
|
+
match do |actual|
|
10
|
+
!actual.nil? && actual.length > 0
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: repo_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Rudy Jacobs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Take the github repositories list, and filter it to ruby libraries.
|
70
|
+
email:
|
71
|
+
- matthewrudyjacobs@gmail.com
|
72
|
+
executables:
|
73
|
+
- repo-parser
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/repo-parser
|
85
|
+
- lib/repo_parser.rb
|
86
|
+
- lib/repo_parser/version.rb
|
87
|
+
- repo_parser.gemspec
|
88
|
+
- spec/repo_parser_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/matthewrudy/repo_parser
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: RepoParser is a code example
|
114
|
+
test_files:
|
115
|
+
- spec/repo_parser_spec.rb
|
116
|
+
- spec/spec_helper.rb
|