Sha256: d96f04d0d56247e8404ec59865f8a751e4a40ebde09fb8f76173f709423f9ce9

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module ReportsKit
  module Reports
    class PropertiesToFilter
      attr_accessor :properties, :context_record

      def initialize(properties, context_record: nil)
        self.properties = properties
        self.context_record = context_record
      end

      def perform(filter_key)
        filter_key = filter_key.to_s
        filter = filters.find { |f| f.key == filter_key }
        raise ArgumentError.new("A filter with key '#{filter_key}' is not configured in this report") unless filter
        filter
      end

      private

      def filters
        @filters ||= ui_filters + series_filters
      end

      def series_filters
        serieses.map(&:filters).flatten
      end

      def ui_filters
        return [] if properties[:ui_filters].blank?
        properties[:ui_filters].map do |ui_filter_properties|
          Reports::Filter.new(ui_filter_properties)
        end
      end

      def serieses
        Reports::Series.new_from_properties!(properties, context_record: context_record)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reports_kit-0.7.1 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.7.0 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.5.0 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.4.1 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.4.0 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.3.3 lib/reports_kit/reports/properties_to_filter.rb
reports_kit-0.3.2 lib/reports_kit/reports/properties_to_filter.rb