Class: SortedSearch::GithubProvider

Inherits:
Provider
  • Object
show all
Defined in:
lib/sorted_search/providers/github_provider.rb

Overview

base class for printers

Instance Attribute Summary

Attributes inherited from Provider

#sorting_criteria

Instance Method Summary collapse

Methods inherited from Provider

#initialize, #pod_from_spec, #provide_sorted_specs

Constructor Details

This class inherits a constructor from SortedSearch::Provider

Instance Method Details

#fetch_dataObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sorted_search/providers/github_provider.rb', line 10

def fetch_data
  super
  pods = []
  @specs.each do |spec|
    pods << pod_from_spec(spec)
  end

  hydra = Typhoeus::Hydra.hydra

  @github_repos = {}
  pods.each do |pod|

    _, username, reponame = *(pod.source_url.match(%r{[:/]([\w\-]+)/([\w\-]+)\.git}))

    request = SortedSearch::GitHub.get_repo(username, reponame) do |response_object|
      @progress_bar.increment

      if response_object
        @github_repos[pod] = response_object
      else
        mash = Hashie::Mash.new
        mash.stargazers_count = 0
        mash.forks = 0
        mash.pushed_at = "0 - Unknown"
        @github_repos[pod] = mash
      end
    end

    hydra.queue request
  end

  hydra.run
end

#sort_specsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sorted_search/providers/github_provider.rb', line 44

def sort_specs
  @github_repos.sort_by do |key, value|
    case @sorting_criteria

      when :stars
        value.stargazers_count.to_i

      when :forks
        value.forks.to_i

      when :activity
        value.pushed_at

      else
        nil
    end
  end
end