Class: CypressViewportUpdater::Viewports
- Inherits:
-
Object
- Object
- CypressViewportUpdater::Viewports
- Defined in:
- app/sidekiq/cypress_viewport_updater/viewports.rb
Constant Summary collapse
- NUM_TOP_VIEWPORTS =
{ mobile: 5, tablet: 5, desktop: 5 }.freeze
Instance Method Summary collapse
- #create(viewport_report:) ⇒ Object
- #desktop ⇒ Object
-
#initialize(user_report:) ⇒ Viewports
constructor
A new instance of Viewports.
- #make_viewport(row:, rank:) ⇒ Object private
- #mobile ⇒ Object
- #tablet ⇒ Object
- #viewports_full? ⇒ Boolean private
- #width_and_height_set?(row) ⇒ Boolean private
Constructor Details
#initialize(user_report:) ⇒ Viewports
Returns a new instance of Viewports.
7 8 9 10 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 7 def initialize(user_report:) @total_users = user_report.data.totals.first.values.first.to_f @viewports = { mobile: [], tablet: [], desktop: [] } end |
Instance Method Details
#create(viewport_report:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 12 def create(viewport_report:) count = { mobile: 0, tablet: 0, desktop: 0 } .data.rows.each do |row| = row.dimensions.first.to_sym if @viewports[].count < NUM_TOP_VIEWPORTS[] && width_and_height_set?(row) count[] += 1 @viewports[] << (row:, rank: count[]) end break if end self end |
#desktop ⇒ Object
38 39 40 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 38 def desktop @viewports[:desktop] end |
#make_viewport(row:, rank:) ⇒ Object (private)
48 49 50 51 52 53 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 48 def (row:, rank:) CypressViewportUpdater:: Viewport.new(row:, rank:, total_users: @total_users) end |
#mobile ⇒ Object
30 31 32 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 30 def mobile @viewports[:mobile] end |
#tablet ⇒ Object
34 35 36 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 34 def tablet @viewports[:tablet] end |
#viewports_full? ⇒ Boolean (private)
55 56 57 58 59 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 55 def @viewports[:mobile].count >= NUM_TOP_VIEWPORTS[:mobile] && @viewports[:tablet].count >= NUM_TOP_VIEWPORTS[:tablet] && @viewports[:desktop].count >= NUM_TOP_VIEWPORTS[:desktop] end |
#width_and_height_set?(row) ⇒ Boolean (private)
44 45 46 |
# File 'app/sidekiq/cypress_viewport_updater/viewports.rb', line 44 def width_and_height_set?(row) row.dimensions[1] != '(not set)' end |