Skip to content

Commit

Permalink
Adds stats
Browse files Browse the repository at this point in the history
  • Loading branch information
veelenga committed May 8, 2017
1 parent 78c2acb commit ef60c5c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Contributions are welcome. Please take a quick look at the [contribution guideli

## HTTP
* [crul](https://github.com/porras/crul) - Command line HTTP client
* [cryload](https://github.com/Sdogruyol/cryload) - HTTP benchmarking tool
* [cryload](https://github.com/sdogruyol/cryload) - HTTP benchmarking tool
* [crystal-cossack](https://github.com/greyblake/crystal-cossack) - Simple flexible HTTP client
* [etag](https://github.com/SuperPaintman/etag) - Library to generate HTTP ETags
* [helmet](https://github.com/EvanHahn/crystal-helmet) - Set security-related HTTP headers
Expand Down
20 changes: 10 additions & 10 deletions spec/readme_spec.cr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require "./spec_helper"
require "spec"
require "uri"
require "../util/readme"

README_PATH = "./README.md"
readme = Readme.new README_PATH
readme = Readme.new

# Enable for debug purpose
# File.write("readme.html", readme.html)

describe "List of Crystal Awesomeness" do
it "has references to awesomeness" do
readme.get_refs(/github\.com/).empty?.should be_false
readme.refs(/github\.com/).empty?.should be_false
end

it "has github references ('https://github.com/path')" do
readme.get_refs(/github\.com/).each do |ref|
readme.refs(/github\.com/).each do |ref|
uri = URI.parse(ref)
uri.scheme.should eq "https"
uri.host.should eq "github.com"
Expand All @@ -22,7 +22,7 @@ describe "List of Crystal Awesomeness" do
end

it "has gitlab references ('https://gitlab.com/path')" do
readme.get_refs(/gitlab\.com/).each do |ref|
readme.refs(/gitlab\.com/).each do |ref|
uri = URI.parse(ref)
uri.scheme.should eq "https"
uri.host.should eq "gitlab.com"
Expand All @@ -32,10 +32,10 @@ describe "List of Crystal Awesomeness" do

it "does not have duplicates" do
prev = nil
readme.get_refs(/git(?:hub|lab)\.com/).map do |ref|
readme.refs(/git(?:hub|lab)\.com/).map do |ref|
uri = URI.parse(ref)
host = uri.host.as String
path = uri.path.as String | Nil
path = uri.path.as String?
"#{host.downcase}#{path.try &.downcase}"
end.sort.each do |ref|
ref.should_not eq prev
Expand All @@ -44,7 +44,7 @@ describe "List of Crystal Awesomeness" do
end

it "has alphabetical case insensitive order" do
readme.get_groups.each do |group|
readme.groups.each do |group|
sorted = group.sort { |x, y| x.downcase <=> y.downcase }
group.each_with_index do |awesome, i|
awesome.should eq sorted[i]
Expand All @@ -54,7 +54,7 @@ describe "List of Crystal Awesomeness" do

context "Document" do
it "does not have trailing spaces" do
File.read_lines(README_PATH).each_with_index do |line, line_number|
File.read_lines(readme.path).each_with_index do |line, line_number|
(line =~ /[ \t]+$/ && line_number + 1).should eq nil
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/spec_helper.cr → util/readme.cr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
require "xml"
require "spec"
require "markdown"

class Readme
getter html : XML::Node
getter path : String

def initialize(path : String)
@html = to_html File.read(path)
def initialize(@path : String = "./README.md")
@html = to_html File.read(@path)
end

def find(xpath)
@html.xpath(xpath)
end

def get_awesomeness
def awesomeness
find("//ul/li/a").as XML::NodeSet
end

def get_refs(selects = nil)
def refs(selects = nil)
set = find("//ul/li/a/@href").as XML::NodeSet
refs = set.map { |node| node.text.as String }
refs.select! { |x| x =~ selects } if selects
refs
end

def get_groups
def groups
set = find("//ul[li]").as XML::NodeSet
set.map do |node|
n = XML.parse(node.to_s).xpath("/ul/li/a[1]/text()").as XML::NodeSet
Expand Down
18 changes: 18 additions & 0 deletions util/stats.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "uri"
require "./readme"

puts "== Crystal Awesome Owner Rank == \n\n"

Readme
.new
.refs(/git(?:hub|lab)\.com/)
.map { |ref| URI.parse(ref).path.as(String?).try &.split(/\//).try &.[1] }
.compact
.reject(&.blank?)
.map(&.downcase)
.group_by(&.itself)
.to_a
.sort_by { |_, entries| -1 * entries.size }
.each_with_index do |heros, i|
puts "#{i + 1}. #{heros.first} (#{heros.last.size} entries)"
end

0 comments on commit ef60c5c

Please sign in to comment.