Class: Ossert::Reference::Base
- Inherits:
-
Object
- Object
- Ossert::Reference::Base
- Defined in:
- lib/ossert/reference.rb
Constant Summary collapse
- CLASSES =
%w(ClassA ClassB ClassC ClassD ClassE).freeze
- PER_PAGE =
20
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#project_names ⇒ Object
readonly
Returns the value of attribute project_names.
-
#representative ⇒ Object
readonly
Returns the value of attribute representative.
Instance Method Summary collapse
-
#initialize(representative, pages) ⇒ Base
constructor
A new instance of Base.
- #prepare_projects! ⇒ Object
Constructor Details
#initialize(representative, pages) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 37 |
# File 'lib/ossert/reference.rb', line 32 def initialize(representative, pages) @representative = representative @pages = pages @project_names = Set.new # 20 each page, total 5907 pages end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
30 31 32 |
# File 'lib/ossert/reference.rb', line 30 def pages @pages end |
#project_names ⇒ Object (readonly)
Returns the value of attribute project_names.
30 31 32 |
# File 'lib/ossert/reference.rb', line 30 def project_names @project_names end |
#representative ⇒ Object (readonly)
Returns the value of attribute representative.
30 31 32 |
# File 'lib/ossert/reference.rb', line 30 def representative @representative end |
Instance Method Details
#prepare_projects! ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ossert/reference.rb', line 41 def prepare_projects! puts "Processing #{self.class.name}" all_pages = pages.to_a.shuffle all_projects = {} (representative / PER_PAGE).times do current_page = all_pages.pop Fetch::BestgemsDailyStat.process_page(current_page) do |rank, downloads, name| all_projects[name] = { rank: rank, downloads: downloads } end end # @project_names.merge all_projects.keys.shuffle.first(representative) @project_names.merge all_projects.sort_by { |_, info| info[:downloads] }.to_h.keys.last(representative) end |