class Contribute::Finder

Constants

ORDER_OPTIONS
Repo
SORT_OPTIONS

Attributes

finder_client[R]
options[R]
query[R]

Public Class Methods

new(query = '', options = {}) click to toggle source
# File lib/contribute/finder.rb, line 8
def initialize(query = '', options = {})
  @finder_client = Contribute::Client.new.octokit
  @query = query
  @options = options
end

Public Instance Methods

find() click to toggle source
# 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 = '*') click to toggle source
# File lib/contribute/finder.rb, line 24
def forks(lo = '*', hi = '*')
  query << " forks:#{lo}..#{hi}"
  self
end
language(name) click to toggle source
# File lib/contribute/finder.rb, line 14
def language(name)
  query << " language:#{name}"
  self
end
order(type) click to toggle source
# 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) click to toggle source
# 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 = '*') click to toggle source
# File lib/contribute/finder.rb, line 19
def stars(lo = '*', hi = '*')
  query << " stars:#{lo}..#{hi}"
  self
end

Private Instance Methods

error_msg(type, valid_otions) click to toggle source
# File lib/contribute/finder.rb, line 52
def error_msg(type, valid_otions)
  "'#{type}' field argument is not valid. Valid inputs: #{valid_otions.join(', ')}"
end