Class: Contribute::Finder
- Inherits:
-
Object
- Object
- Contribute::Finder
- 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
- #find ⇒ Object
- #forks(lo = '*', hi = '*') ⇒ Object
-
#initialize(query = '', options = {}) ⇒ Finder
constructor
A new instance of Finder.
- #language(name) ⇒ Object
- #order(type) ⇒ Object
- #sort_by(field) ⇒ Object
- #stars(lo = '*', hi = '*') ⇒ Object
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 = '', = {}) @finder_client = Contribute::Client.new.octokit @query = query = end |
Instance Method Details
#find ⇒ Object
41 42 43 44 45 46 |
# File 'lib/contribute/finder.rb', line 41 def find results = finder_client.search_repositories query, 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 [: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 [: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 |