Class: Spotlight::Analytics::AggregationComponent
- Inherits:
 - 
      ViewComponent::Base
      
        
- Object
 - ViewComponent::Base
 - Spotlight::Analytics::AggregationComponent
 
 
- Defined in:
 - app/components/spotlight/analytics/aggregation_component.rb
 
Overview
Display Analytics aggregations as table
Instance Method Summary collapse
- #display_fields ⇒ Object
 - #format_field(key, value) ⇒ Object
 - 
  
    
      #initialize(data:, exclude_fields: nil)  ⇒ AggregationComponent 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of AggregationComponent.
 - #render? ⇒ Boolean
 
Constructor Details
#initialize(data:, exclude_fields: nil) ⇒ AggregationComponent
Returns a new instance of AggregationComponent.
      7 8 9 10 11  | 
    
      # File 'app/components/spotlight/analytics/aggregation_component.rb', line 7 def initialize(data:, exclude_fields: nil) super @exclude_fields = exclude_fields @data = data end  | 
  
Instance Method Details
#display_fields ⇒ Object
      17 18 19 20 21 22  | 
    
      # File 'app/components/spotlight/analytics/aggregation_component.rb', line 17 def display_fields return @data unless @exclude_fields filtered_data = @data.to_h.except(*@exclude_fields) OpenStruct.new(filtered_data) end  | 
  
#format_field(key, value) ⇒ Object
      24 25 26 27 28 29 30 31 32 33 34  | 
    
      # File 'app/components/spotlight/analytics/aggregation_component.rb', line 24 def format_field(key, value) if value.is_a?(Float) if key.to_s.downcase.include?('rate') "#{(value * 100).to_i}%" else Kernel.format('%.2f', value) end else value end end  | 
  
#render? ⇒ Boolean
      13 14 15  | 
    
      # File 'app/components/spotlight/analytics/aggregation_component.rb', line 13 def render? display_fields.to_h.present? end  |