repo_parser 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c34e220511f3a91543782ab7559e993bad5092d1
4
- data.tar.gz: 17e7bef1af5736910c5ab676dbf2af677029cd87
3
+ metadata.gz: cdeffd4817a0819085de78226f215116fbf5508f
4
+ data.tar.gz: f68e267c32a89bb45ccf96c5ff33e671f4aea70b
5
5
  SHA512:
6
- metadata.gz: 4ead8bf1f8ff620199b910d7e03231596d219c8afbc37a2ccba345e97b33fe04871486e58d5800ab6017b5d212279d6ca91313052a1e2626c15c6ac182007bfe
7
- data.tar.gz: 1ffd043b51c7697b2e4f705d6694246ffec436abcb412907e7b046f0de1e4ae7fb396fef140d53488c6ae6f3529c7ab403777dedcbff1f74d7f76c5dcadd46fc
6
+ metadata.gz: f0bdc0d141b26ccfe5e13a50eae2624e0f2b115d0f005e270222b869679b81becf5338ce26eb9486fa8b5b2362d32dfcb4f7349fec573dc25eef05b7966eea2b
7
+ data.tar.gz: cbc6ad84326cf79da1480ba907684d463cc24ae47c23fffea1fb9e8297cf6456e62557fc2065a595e9d901738e7de15681487a1a943e8d57dc7c67d06b3a46a2
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ # allow class Abc < Struct.new(:def)
2
+ Style/StructInheritance:
3
+ Enabled: false
data/README.md CHANGED
@@ -14,7 +14,7 @@ Take response of https://api.github.com/repositories and perform the following a
14
14
 
15
15
  $ gem install repo_parser
16
16
 
17
- $ repo-parser
17
+ $ repo_parser
18
18
 
19
19
  RepoParser
20
20
  ==========
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
7
-
6
+ task default: :spec
@@ -3,4 +3,4 @@
3
3
  require 'repo_parser'
4
4
 
5
5
  result = RepoParser.run
6
- puts result.to_string
6
+ puts result
data/lib/repo_parser.rb CHANGED
@@ -6,13 +6,24 @@ require 'httparty'
6
6
  # and sorting it.
7
7
  module RepoParser
8
8
  def self.run
9
- repos = Parser.call(Fetcher.call)
10
- sorted = Sorter.call(Filterer.call(repos))
11
- Result.new(sorted)
9
+ repos = chain(Fetcher, Parser, Filterer, Sorter)
10
+ Result.new(repos)
12
11
  end
13
12
 
13
+ def self.chain(*processors)
14
+ # the first is called with no args
15
+ value = processors.shift.call
16
+
17
+ processors.each do |proc|
18
+ value = proc.call(value)
19
+ end
20
+
21
+ value
22
+ end
23
+
24
+ # Result stores the result of a parsing
14
25
  class Result < Struct.new(:repositories)
15
- def to_string
26
+ def to_s
16
27
  lines = []
17
28
 
18
29
  lines << <<-STRING
@@ -20,15 +31,7 @@ module RepoParser
20
31
  ==========
21
32
  STRING
22
33
 
23
- repositories.each do |repo|
24
- lines << <<-STRING
25
- #{repo.name}:
26
- name: #{repo.name}
27
- url: #{repo.url}
28
- owner: #{repo.owner}
29
- ----------
30
- STRING
31
- end
34
+ lines += repositories.map(&:to_s)
32
35
 
33
36
  lines << <<-STRING
34
37
  Total: #{repositories.length}
@@ -58,7 +61,17 @@ module RepoParser
58
61
  end
59
62
 
60
63
  # Repository represents a repository
61
- Repository = Struct.new(:name, :url, :owner, :fork)
64
+ class Repository < Struct.new(:name, :url, :owner, :fork)
65
+ def to_s
66
+ <<-STRING
67
+ #{name}:
68
+ name: #{name}
69
+ url: #{url}
70
+ owner: #{owner}
71
+ ----------
72
+ STRING
73
+ end
74
+ end
62
75
 
63
76
  # Filterer filters non-matching repositories
64
77
  class Filterer
@@ -1,3 +1,6 @@
1
+ # RepoParser is a coding test
2
+ # involving scraping some github json,
3
+ # and sorting it.
1
4
  module RepoParser
2
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3'
3
6
  end
data/repo_parser.gemspec CHANGED
@@ -9,13 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Matthew Rudy Jacobs']
10
10
  spec.email = ['matthewrudyjacobs@gmail.com']
11
11
  spec.summary = 'RepoParser is a code example'
12
- spec.description = 'Take the github repositories list, and filter it to ruby libraries.'
13
12
  spec.homepage = 'https://github.com/matthewrudy/repo_parser'
14
13
  spec.license = 'MIT'
15
14
 
16
15
  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)/})
16
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
18
  spec.require_paths = ['lib']
20
19
 
21
20
  spec.add_dependency 'httparty', '~> 0.13.3'
@@ -28,4 +28,12 @@ RSpec.describe RepoParser do
28
28
 
29
29
  expect(ruby_names).to eq names
30
30
  end
31
+
32
+ it 'returns only non-forked repositories' do
33
+ repositories = RepoParser.run.repositories
34
+
35
+ forked = repositories.select(&:fork)
36
+
37
+ expect(forked).to be_empty
38
+ end
31
39
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'repo_parser'
3
3
 
4
- RSpec.configure do |c|
5
- c.disable_monkey_patching!
6
- end
4
+ RSpec.configure(&:disable_monkey_patching!)
7
5
 
8
6
  RSpec::Matchers.define :be_present do
9
7
  match do |actual|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repo_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Rudy Jacobs
@@ -66,22 +66,23 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Take the github repositories list, and filter it to ruby libraries.
69
+ description:
70
70
  email:
71
71
  - matthewrudyjacobs@gmail.com
72
72
  executables:
73
- - repo-parser
73
+ - repo_parser
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".rspec"
79
+ - ".rubocop.yml"
79
80
  - ".travis.yml"
80
81
  - Gemfile
81
82
  - LICENSE.txt
82
83
  - README.md
83
84
  - Rakefile
84
- - bin/repo-parser
85
+ - bin/repo_parser
85
86
  - lib/repo_parser.rb
86
87
  - lib/repo_parser/version.rb
87
88
  - repo_parser.gemspec