Sha256: 45a8fe6be94738f004444c635a29c9bf416d38f4d2c4173d9f3c195fbc445b8c

Contents?: true

Size: 836 Bytes

Versions: 20

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

module Spotlight
  module Analytics
    # Display Analytics aggregations as table
    class AggregationComponent < ViewComponent::Base
      def initialize(data:, exclude_fields: nil)
        super
        @exclude_fields = exclude_fields
        @data = data
      end

      def render?
        display_fields.to_h.present?
      end

      def display_fields
        return @data unless @exclude_fields

        filtered_data = @data.to_h.except(*@exclude_fields)
        OpenStruct.new(filtered_data)
      end

      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
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
blacklight-spotlight-5.0.0.pre.alpha3 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-5.0.0.pre.alpha2 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-5.0.0.pre.alpha1 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.7.1 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.7.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.6.1 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.6.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.5.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.4.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.6 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.5 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.4 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.3 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.2 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.1 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.3.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.2.0 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.1.2 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.1.1 app/components/spotlight/analytics/aggregation_component.rb
blacklight-spotlight-4.1.0 app/components/spotlight/analytics/aggregation_component.rb