readme-score 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9349f1f7324a4fd2257ec0d917e526bf42bb3d38
4
+ data.tar.gz: aa9b06e70969999360ea05cb4a41085a26001a56
5
+ SHA512:
6
+ metadata.gz: fe0b9f3a1663f6a59951e93522804fec27e67e84d5cccac980e8eefcfa75bda1fedfeec96db1d375d26799a410fad130802a13ec8eae524a3d667ebebb2c4c64
7
+ data.tar.gz: e2667d4bfc8742c1fe975fbdfc33626c9feda8bb4428e77a6aca5b55083f723162df2c1cc13c018e81517e5fb4f447113e9681106d5523f315164edc72fb332f
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ .env
18
+ data/cache
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in readme-score.gemspec
4
+ gemspec
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ readme-score (0.0.2)
5
+ nokogiri (>= 1.6.0)
6
+ octokit (>= 3.2.0)
7
+ redcarpet (>= 3.1.0)
8
+ unirest (>= 1.1.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.3.6)
14
+ crack (0.4.2)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.2.5)
17
+ dotenv (1.0.2)
18
+ faraday (0.9.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ json (1.8.1)
21
+ mime-types (1.25.1)
22
+ mini_portile (0.6.0)
23
+ multipart-post (2.0.0)
24
+ nokogiri (1.6.3.1)
25
+ mini_portile (= 0.6.0)
26
+ octokit (3.4.2)
27
+ sawyer (~> 0.5.3)
28
+ rake (10.3.2)
29
+ rdoc (4.1.2)
30
+ json (~> 1.4)
31
+ redcarpet (3.2.0)
32
+ rest-client (1.6.8)
33
+ mime-types (~> 1.16)
34
+ rdoc (>= 2.4.2)
35
+ rspec (3.1.0)
36
+ rspec-core (~> 3.1.0)
37
+ rspec-expectations (~> 3.1.0)
38
+ rspec-mocks (~> 3.1.0)
39
+ rspec-core (3.1.7)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-expectations (3.1.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-mocks (3.1.3)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-support (3.1.2)
47
+ safe_yaml (1.0.4)
48
+ sawyer (0.5.5)
49
+ addressable (~> 2.3.5)
50
+ faraday (~> 0.8, < 0.10)
51
+ unirest (1.1.2)
52
+ addressable (~> 2.3.5)
53
+ json (~> 1.8.1)
54
+ rest-client (~> 1.6.7)
55
+ webmock (1.19.0)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.5)
64
+ dotenv
65
+ rake
66
+ readme-score!
67
+ rspec
68
+ webmock
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Clay Allsopp
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.
@@ -0,0 +1,87 @@
1
+ # ReadmeScore
2
+
3
+ [![Build Status](https://travis-ci.org/clayallsopp/readme-score.svg)](https://travis-ci.org/clayallsopp/readme-score)
4
+ [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=clayallsopp/readme-score&bust=1)](http://clayallsopp.github.io/readme-score?url=clayallsopp/readme-score)
5
+
6
+ Gives a complexity score for a README.
7
+
8
+ Check scores of any repo in your browser: [http://scoreme.report](http://scoreme.report)
9
+
10
+ There's an [HTTP API too](http://github.com/clayallsopp/readme-score-api)!
11
+
12
+
13
+ Example score:
14
+
15
+ | Repo | Score |
16
+ |---------------------------------------------------------------|-------|
17
+ | https://github.com/RolandasRazma/RRFPSBar | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=RolandasRazma/RRFPSBar)](http://clayallsopp.github.io/readme-score?url=RolandasRazma/RRFPSBar) |
18
+ | https://github.com/JRG-Developer/MediaRSSParser | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=JRG-Developer/MediaRSSParser)](http://clayallsopp.github.io/readme-score?url=JRG-Developer/MediaRSSParser) |
19
+ | https://github.com/ruslanskorb/RSDayFlow | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=ruslanskorb/RSDayFlow)](http://clayallsopp.github.io/readme-score?url=ruslanskorb/RSDayFlow) |
20
+ | https://github.com/samnung/AFHTTPFileUpdateOperation | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=samnung/AFHTTPFileUpdateOperation)](http://clayallsopp.github.io/readme-score?url=samnung/AFHTTPFileUpdateOperation) |
21
+ | https://github.com/schneiderandre/ASCFlatUIColor | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=schneiderandre/ASCFlatUIColor)](http://clayallsopp.github.io/readme-score?url=schneiderandre/ASCFlatUIColor) |
22
+ | https://github.com/daltoniam/BootstrapUIKit | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=daltoniam/BootstrapUIKit)](http://clayallsopp.github.io/readme-score?url=daltoniam/BootstrapUIKit) |
23
+ | https://github.com/AFNetworking/AFNetworking | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=AFNetworking/AFNetworking)](http://clayallsopp.github.io/readme-score?url=AFNetworking/AFNetworking) |
24
+ | https://github.com/tomersh/AppleGuice | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=tomersh/AppleGuice)](http://clayallsopp.github.io/readme-score?url=tomersh/AppleGuice) |
25
+ | https://github.com/kevindelord/DKHelper | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=kevindelord/DKHelper)](http://clayallsopp.github.io/readme-score?url=kevindelord/DKHelper) |
26
+ | https://github.com/saturngod/IAPHelper | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=saturngod/IAPHelper)](http://clayallsopp.github.io/readme-score?url=saturngod/IAPHelper) |
27
+ | https://github.com/alskipp/ASValueTrackingSlider | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=alskipp/ASValueTrackingSlider)](http://clayallsopp.github.io/readme-score?url=alskipp/ASValueTrackingSlider) |
28
+ | https://github.com/phranck/CNTreeNode | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=phranck/CNTreeNode)](http://clayallsopp.github.io/readme-score?url=phranck/CNTreeNode) |
29
+ | https://github.com/dasdom/DDHDynamicViewControllerTransitions | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=dasdom/DDHDynamicViewControllerTransitions)](http://clayallsopp.github.io/readme-score?url=dasdom/DDHDynamicViewControllerTransitions) |
30
+ | https://github.com/RestKit/RestKit | [![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=RestKit/RestKit)](http://clayallsopp.github.io/readme-score?url=RestKit/RestKit) |
31
+
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ gem 'readme-score'
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install readme-score
46
+
47
+ ## Usage
48
+
49
+ Pass in a URL:
50
+
51
+ ```ruby
52
+ url = "https://raw.githubusercontent.com/AFNetworking/AFNetworking/master/README.md"
53
+ score = ReadmeScore.for(url)
54
+ score.total_score
55
+ # => 95
56
+ ```
57
+
58
+ Pass in a Github Repo:
59
+
60
+ ```ruby
61
+ score = ReadmeScore.for("afnetworking/afnetworking")
62
+ score.total_score
63
+ # => 95
64
+ ```
65
+
66
+ Pass in HTML:
67
+
68
+ ```ruby
69
+ html = "AFNetworking is a delightful networking library for iOS and Mac OS X...."
70
+ score = ReadmeScore.for(html)
71
+ score.total_score
72
+ # => 95
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ ### Settings
78
+
79
+ - `ReadmeScore.use_github_api = <boolean>` - whether or not to use the Github API when loading a Github repo's readme. If `false`, will attempt to find the correct readme URL without the API (which could fail unexpectedly). Defaults to `true`
80
+
81
+ - `ReadmeScore.github_api_token = <token>` - a token to use with the Github API. Supercedes the ENV variable.
82
+
83
+ ### Environment Variables
84
+
85
+ | ENV | Description |
86
+ |---------------------------------------------------------------|-------|
87
+ | READMESCORE_GITHUB_TOKEN | If scoring a Github repo, ReadmeScore will try to grab the canonical representation via the Github API. By default, [unauthenticated requests are limited](https://developer.github.com/v3/#rate-limiting) to 60/hour. Set this env variable to increase that limited to 5k/hour. |
@@ -0,0 +1,133 @@
1
+ ROOT = File.dirname(__FILE__)
2
+
3
+ $:.unshift(File.join(ROOT, 'lib'))
4
+ require 'readme-score'
5
+
6
+ require "bundler/gem_tasks"
7
+
8
+ require 'json'
9
+ require 'ostruct'
10
+ require 'fileutils'
11
+
12
+ require 'dotenv'
13
+ Dotenv.load
14
+
15
+ def loaded_seed_data
16
+ JSON.parse(IO.read("data/seed.json")).map {|d|
17
+ OpenStruct.new(d).tap { |o|
18
+ o.repo_name = o.readme.split("/")[-1]
19
+ o.cache_path = File.join(ROOT, "data", "cache", "#{o.repo_name}.md")
20
+ }
21
+ }
22
+ end
23
+
24
+ def seed_data(d)
25
+ buffer = "------\n"
26
+ buffer << d.output_metrics
27
+ buffer << "------\n"
28
+ buffer << d.html
29
+ end
30
+
31
+ def analyze(document_tuples)
32
+ document_tuples.each {|seed, d|
33
+ # puts seed_data(d)
34
+ }
35
+ repo_names = document_tuples.map(&:first).map(&:repo_name)
36
+ scores = document_tuples.map(&:first).map(&:score)
37
+ documents = document_tuples.map(&:last)
38
+
39
+ Statsample::Analysis.store(Statsample::Regression::Multiple) do |suite|
40
+ metric_hash = {}
41
+ ReadmeScore::Document::Metrics::EQUATION_METRICS.each do |metric|
42
+ puts metric
43
+ metric_hash[metric] = documents.map(&:text_metrics).map(&metric.to_proc).to_scale
44
+ end
45
+ puts metric_hash
46
+ ds = suite.dataset(metric_hash)
47
+ ds['score'] = scores.to_scale
48
+ @regression = suite.lr(ds, 'score')
49
+ end
50
+
51
+ Statsample::Analysis.run_batch
52
+
53
+ equation = ReadmeScore::Equation.new(@regression.constant, @regression.coeffs)
54
+
55
+ differentials = []
56
+ documents.each.with_index {|d, i|
57
+ puts repo_names[i]
58
+ predection = scores[i]
59
+ calculated = equation.value_for(d.text_metrics)
60
+ differentials << (predection - calculated).abs
61
+ puts "Predection: #{predection}; Equation: #{calculated}"
62
+ }
63
+ puts "Average diff: #{differentials.to_scale.mean}"
64
+
65
+ ReadmeScore::Equation.save_as_default!(equation)
66
+ end
67
+
68
+ desc "Analyze seed data"
69
+ task :seed do
70
+ seed_data = loaded_seed_data
71
+ documents = seed_data.map {|d|
72
+ [d, ReadmeScore::Document.load(d.readme)]
73
+ }
74
+ analyze(documents)
75
+ end
76
+
77
+ task :seed_from_cache do
78
+ seed_data = loaded_seed_data
79
+ #seed_data = [seed_data[0]]
80
+ documents = seed_data.map {|d|
81
+ cached_markdown = IO.read(d.cache_path)
82
+ html = ReadmeScore::Document::Parser.new(cached_markdown).to_html
83
+ [d, ReadmeScore::Document.new(html)]
84
+ }
85
+ analyze(documents)
86
+ end
87
+
88
+ desc "Cache the seed data locally"
89
+ task :cache_seed do
90
+ seed_data = loaded_seed_data
91
+ seed_data.each {|d|
92
+ FileUtils.mkdir_p(File.dirname(d.cache_path))
93
+ loader = ReadmeScore::Document::Loader.new(d.readme)
94
+ loader.load!
95
+ File.open(d.cache_path, 'w') {|f| f.write(loader.response.body) }
96
+ }
97
+ end
98
+
99
+ task :example do
100
+ d = ReadmeScore::Document.load("http://github.com/usepropeller/applebot")
101
+ puts d.score.total_score
102
+ end
103
+
104
+ task :compare_seeds do
105
+ seed_data = loaded_seed_data
106
+ documents = seed_data.map {|d|
107
+ html = IO.read(d.cache_path)
108
+ [d, ReadmeScore::Document.new(html)]
109
+ # [d, ReadmeScore::Document.load(d.readme)]
110
+ }
111
+ differentials = []
112
+ documents.each {|seed, d|
113
+ puts seed.readme
114
+ predection = seed.score
115
+ calculated = d.score.total_score
116
+ differentials << (predection - calculated).abs
117
+ puts "Predection: #{predection}; Equation: #{calculated}"
118
+ }
119
+ puts differentials
120
+ puts "Average diff: #{differentials.to_scale.mean}"
121
+ end
122
+
123
+ task :console do
124
+ require 'irb'
125
+ ARGV.clear
126
+ IRB.start
127
+ end
128
+
129
+ task :default => [:spec]
130
+ desc 'run Rspec specs'
131
+ task :spec do
132
+ sh 'rspec spec'
133
+ end
@@ -0,0 +1,58 @@
1
+ [
2
+ {
3
+ "readme": "https://github.com/RolandasRazma/RRFPSBar",
4
+ "score": 30
5
+ },
6
+ {
7
+ "readme": "https://github.com/JRG-Developer/MediaRSSParser",
8
+ "score": 50
9
+ },
10
+ {
11
+ "readme": "https://github.com/ruslanskorb/RSDayFlow",
12
+ "score": 40
13
+ },
14
+ {
15
+ "readme": "https://github.com/samnung/AFHTTPFileUpdateOperation",
16
+ "score": 25
17
+ },
18
+ {
19
+ "readme": "https://github.com/schneiderandre/ASCFlatUIColor",
20
+ "score": 65
21
+ },
22
+ {
23
+ "readme": "https://github.com/daltoniam/BootstrapUIKit",
24
+ "score": 45
25
+ },
26
+ {
27
+ "readme": "https://github.com/AFNetworking/AFNetworking",
28
+ "score": 100
29
+ },
30
+ {
31
+ "readme": "https://github.com/tomersh/AppleGuice",
32
+ "score": 80
33
+ },
34
+ {
35
+ "readme": "https://github.com/kevindelord/DKHelper",
36
+ "score": 10
37
+ },
38
+ {
39
+ "readme": "https://github.com/saturngod/IAPHelper",
40
+ "score": 60
41
+ },
42
+ {
43
+ "readme": "https://github.com/alskipp/ASValueTrackingSlider",
44
+ "score": 100
45
+ },
46
+ {
47
+ "readme": "https://github.com/phranck/CNTreeNode",
48
+ "score": 30
49
+ },
50
+ {
51
+ "readme": "https://github.com/dasdom/DDHDynamicViewControllerTransitions",
52
+ "score": 90
53
+ },
54
+ {
55
+ "readme": "https://github.com/RestKit/RestKit",
56
+ "score": 100
57
+ }
58
+ ]
@@ -0,0 +1,47 @@
1
+ require 'nokogiri'
2
+ require 'unirest'
3
+ require 'redcarpet'
4
+ require 'octokit'
5
+
6
+ require 'json'
7
+
8
+ require "readme-score/version"
9
+ require "readme-score/util"
10
+ require "readme-score/document"
11
+
12
+ module ReadmeScore
13
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
14
+
15
+ module_function
16
+ def for(url_or_html)
17
+ document(url_or_html).score
18
+ end
19
+
20
+ def document(url_or_html)
21
+ document = nil
22
+ if Document::Loader.is_url?(url_or_html)
23
+ document = Document.load(url_or_html)
24
+ elsif Document::Loader.is_github_repo_slug?(url_or_html)
25
+ document = Document.load("http://github.com/#{url_or_html}")
26
+ else
27
+ document = Document.new(url_or_html)
28
+ end
29
+ document
30
+ end
31
+
32
+ def use_github_api?
33
+ !@reject_github_api
34
+ end
35
+
36
+ def use_github_api=(use_github_api)
37
+ @reject_github_api = !use_github_api
38
+ end
39
+
40
+ def github_api_token=(github_api_token)
41
+ @github_api_token = github_api_token
42
+ end
43
+
44
+ def github_api_token
45
+ @github_api_token || ENV['READMESCORE_GITHUB_TOKEN']
46
+ end
47
+ end