Class: Ossert::Fetch::Bestgems
- Inherits:
-
Object
- Object
- Ossert::Fetch::Bestgems
- Extended by:
- Forwardable
- Defined in:
- lib/ossert/fetch/bestgems.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #daily_downloads ⇒ Object
- #daily_ranking ⇒ Object
-
#initialize(project) ⇒ Bestgems
constructor
A new instance of Bestgems.
- #process ⇒ Object
- #process_daily_downloads ⇒ Object
- #process_delta_downloads ⇒ Object
- #process_total_downloads ⇒ Object
- #total_downloads ⇒ Object
- #total_ranking ⇒ Object
Constructor Details
#initialize(project) ⇒ Bestgems
Returns a new instance of Bestgems.
33 34 35 36 |
# File 'lib/ossert/fetch/bestgems.rb', line 33 def initialize(project) @client = SimpleClient.new('http://bestgems.org/api/v1/') @project = project end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
28 29 30 |
# File 'lib/ossert/fetch/bestgems.rb', line 28 def client @client end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
28 29 30 |
# File 'lib/ossert/fetch/bestgems.rb', line 28 def project @project end |
Instance Method Details
#daily_downloads ⇒ Object
42 43 44 |
# File 'lib/ossert/fetch/bestgems.rb', line 42 def daily_downloads client.get("gems/#{project.rubygems_alias}/daily_downloads.json") end |
#daily_ranking ⇒ Object
50 51 52 |
# File 'lib/ossert/fetch/bestgems.rb', line 50 def daily_ranking client.get("gems/#{project.rubygems_alias}/daily_ranking.json") end |
#process ⇒ Object
54 55 56 57 58 |
# File 'lib/ossert/fetch/bestgems.rb', line 54 def process process_total_downloads process_daily_downloads process_delta_downloads end |
#process_daily_downloads ⇒ Object
74 75 76 77 78 79 |
# File 'lib/ossert/fetch/bestgems.rb', line 74 def process_daily_downloads daily_downloads.each do |daily| downloads_saved = community.quarters[daily['date']].delta_downloads.to_i community.quarters[daily['date']].delta_downloads = downloads_saved + daily['daily_downloads'] end end |
#process_delta_downloads ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/ossert/fetch/bestgems.rb', line 81 def process_delta_downloads prev_downloads_delta = 0 community.quarters.each_sorted do |start_date, stat| prev_downloads_delta = stat.delta_downloads.to_i - prev_downloads_delta community.quarters[start_date].download_divergence = divergence( prev_downloads_delta, @downloads_till_now['total_downloads'] ) end end |
#process_total_downloads ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ossert/fetch/bestgems.rb', line 60 def process_total_downloads @downloads_till_now = nil total_downloads.each do |total| @downloads_till_now = total unless @downloads_till_now quarter_downloads = community.quarters[total['date']] quarter_downloads.total_downloads = [ quarter_downloads.total_downloads.to_i, total['total_downloads'] ].max end community.total.total_downloads = @downloads_till_now['total_downloads'] end |
#total_downloads ⇒ Object
38 39 40 |
# File 'lib/ossert/fetch/bestgems.rb', line 38 def total_downloads client.get("gems/#{project.rubygems_alias}/total_downloads.json") end |
#total_ranking ⇒ Object
46 47 48 |
# File 'lib/ossert/fetch/bestgems.rb', line 46 def total_ranking client.get("gems/#{project.rubygems_alias}/total_ranking.json") end |