Module: ItamaeSonar
- Defined in:
- lib/itamae-sonar/version.rb,
lib/itamae-sonar.rb
Overview
ItamaeSonar
Constant Summary collapse
- RUBOTY_SEARCH_CONDITION =
'itamae-'
- VERSION =
'1.0.1'
Class Method Summary collapse
- .author_ranking(limit = 5) ⇒ Object
- .info(gem_name) ⇒ Object
- .random ⇒ Object
- .ranking(limit = 5) ⇒ Object
- .search(query) ⇒ Object
Class Method Details
.author_ranking(limit = 5) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/itamae-sonar.rb', line 70 def self.(limit = 5) search(RUBOTY_SEARCH_CONDITION) .map { |e|{ authors: e['authors'], downloads: e['downloads'] } } .group_by { |e| e[:authors] } .map { |key, values| { authors: key, downloads: values.reduce(0) { |a, e|a + e[:downloads] } } }.sort_by { |e| -e[:downloads] } .take(limit) end |
.info(gem_name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/itamae-sonar.rb', line 24 def self.info(gem_name) gem_info = Gems.info(gem_name) { name: gem_info['name'], desc: gem_info['info'], downloads: gem_info['downloads'], rubygems_uri: gem_info['project_uri'], homepage_uri: gem_info['homepage_uri'] } end |
.random ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/itamae-sonar.rb', line 47 def self.random gem_info = search(RUBOTY_SEARCH_CONDITION).sample { name: gem_info['name'], desc: gem_info['info'], downloads: gem_info['downloads'], rubygems_uri: gem_info['project_uri'], homepage_uri: gem_info['homepage_uri'] } end |
.ranking(limit = 5) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/itamae-sonar.rb', line 58 def self.ranking(limit = 5) search(RUBOTY_SEARCH_CONDITION) .map { |e| { name: e['name'], downloads: e['downloads'].to_i, authors: e['authors'] } }.sort_by { |e|-e[:downloads] } .take(limit) end |
.search(query) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/itamae-sonar.rb', line 35 def self.search(query) results = [] page = 1 loop { ret = Gems.search_with_page(query, page) break if ret.empty? results += ret page += 1 } results end |