Class: Contribute::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/contribute/finder.rb

Defined Under Namespace

Classes: Repo

Constant Summary collapse

SORT_OPTIONS =
%w(created updated stars forks).freeze
ORDER_OPTIONS =
%w(desc asc).freeze

Instance Method Summary collapse

Constructor Details

#initialize(query = '', options = {}) ⇒ Finder

Returns a new instance of Finder.



8
9
10
11
12
# File 'lib/contribute/finder.rb', line 8

def initialize(query = '', options = {})
  @finder_client = Contribute::Client.new.octokit
  @query = query
  @options = options
end

Instance Method Details

#findObject



41
42
43
44
45
46
# File 'lib/contribute/finder.rb', line 41

def find
  results = finder_client.search_repositories query, options
  results['items'].map do |r|
    Repo.new(r['full_name'], r['name'], r['size'], r['watchers'], r['open_issues'])
  end
end

#forks(lo = '*', hi = '*') ⇒ Object



24
25
26
27
# File 'lib/contribute/finder.rb', line 24

def forks(lo = '*', hi = '*')
  query << " forks:#{lo}..#{hi}"
  self
end

#language(name) ⇒ Object



14
15
16
17
# File 'lib/contribute/finder.rb', line 14

def language(name)
  query << " language:#{name}"
  self
end

#order(type) ⇒ Object



35
36
37
38
39
# File 'lib/contribute/finder.rb', line 35

def order(type)
  raise error_msg('order', ORDER_OPTIONS) unless ORDER_OPTIONS.include? type
  options[:order] = type
  self
end

#sort_by(field) ⇒ Object



29
30
31
32
33
# File 'lib/contribute/finder.rb', line 29

def sort_by(field)
  raise error_msg('sort', SORT_OPTIONS) unless SORT_OPTIONS.include? field
  options[:sort] = field
  self
end

#stars(lo = '*', hi = '*') ⇒ Object



19
20
21
22
# File 'lib/contribute/finder.rb', line 19

def stars(lo = '*', hi = '*')
  query << " stars:#{lo}..#{hi}"
  self
end