diff options
| -rwxr-xr-x | bin/shogun | 12 | ||||
| -rw-r--r-- | lib/shogun.rb | 5 | ||||
| -rw-r--r-- | lib/shogun/github_score.rb | 21 | ||||
| -rw-r--r-- | spec/shogun/github_score_spec.rb | 2 |
4 files changed, 22 insertions, 18 deletions
diff --git a/bin/shogun b/bin/shogun new file mode 100755 index 0000000..7bc5192 --- /dev/null +++ b/bin/shogun @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby + +$LOAD_PATH.unshift("#{__dir__}/../lib") + +require "shogun" + +if ARGV.count < 1 + puts "Usage: #{ARGV[0]} USERNAME" + exit 0 +end + +puts Shogun::GitHubScore.new(ARGV[0]).score diff --git a/lib/shogun.rb b/lib/shogun.rb index 818e0a5..05b1a6a 100644 --- a/lib/shogun.rb +++ b/lib/shogun.rb @@ -3,3 +3,8 @@ require "uri" require "json" require "shogun/github_score" + +module Shogun + class UserNotFound < ArgumentError + end +end diff --git a/lib/shogun/github_score.rb b/lib/shogun/github_score.rb index 48947a0..22019ec 100644 --- a/lib/shogun/github_score.rb +++ b/lib/shogun/github_score.rb @@ -1,8 +1,5 @@ module Shogun - class UserNotFound < ArgumentError - end - - class GithubScore + class GitHubScore DEFAULT_POINTS = { "IssuesEvent" => 1, "IssueCommentEvent" => 2, @@ -18,7 +15,9 @@ module Shogun end def score - calculate_score_for(events) + events.sum do |event| + points.fetch(event["type"], 1) + end end private @@ -35,17 +34,5 @@ module Shogun JSON.parse(response.body) end - - def calculate_score_for(events) - grouped = events.group_by { |h| h["type"] }.values - score = grouped.map { |g| - event_type = g.first["type"].strip - event_score = points[event_type] || 1 - event_score * g.count - }.sum - score - end end - - end diff --git a/spec/shogun/github_score_spec.rb b/spec/shogun/github_score_spec.rb index 60deb11..dd71d65 100644 --- a/spec/shogun/github_score_spec.rb +++ b/spec/shogun/github_score_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Shogun::GithubScore do +RSpec.describe Shogun::GitHubScore do describe "#score" do subject(:github_score) { described_class.new(handle) } let(:handle) { "tenderlove" } |
