Sha256: 6891388e7a83c9ff356feef0e9e0d312287dcd03e7c8b6018aecdec5e4d99a36

Contents?: true

Size: 1.06 KB

Versions: 25

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
module Hyrax
  class ChartData
    attr_reader :data
    def initialize(data)
      @data = data
    end

    def drilldown
      data.each_with_object([]) do |(k, v), arr|
        arr << Value.new(k, v).drilldown_value
      end.compact
    end

    def series
      data.each_with_object([]) do |(k, v), arr|
        arr << Value.new(k, v).series_value
      end
    end

    class Value
      def initialize(key, value)
        @key = key
        @value = value
      end

      def series_value
        if @value.is_a?(Hash)
          drilldown_hash
        else
          series_hash
        end
      end

      def drilldown_value
        return nil unless @value.is_a?(Hash)
        {
          name: @key,
          id: @key,
          data: @value.to_a
        }
      end

      private

      def drilldown_hash
        {
          name: @key,
          y: @value.values.inject(&:+),
          drilldown: @key
        }
      end

      def series_hash
        {
          name: @key,
          y: @value
        }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/values/hyrax/chart_data.rb
hyrax-5.0.0 app/values/hyrax/chart_data.rb
hyrax-5.0.0.rc3 app/values/hyrax/chart_data.rb
hyrax-5.0.0.rc2 app/values/hyrax/chart_data.rb
hyrax-5.0.0.rc1 app/values/hyrax/chart_data.rb
hyrax-3.6.0 app/values/hyrax/chart_data.rb
hyrax-4.0.0 app/values/hyrax/chart_data.rb
hyrax-4.0.0.rc3 app/values/hyrax/chart_data.rb
hyrax-4.0.0.rc2 app/values/hyrax/chart_data.rb
hyrax-4.0.0.rc1 app/values/hyrax/chart_data.rb
hyrax-3.5.0 app/values/hyrax/chart_data.rb
hyrax-4.0.0.beta2 app/values/hyrax/chart_data.rb
hyrax-3.4.2 app/values/hyrax/chart_data.rb
hyrax-4.0.0.beta1 app/values/hyrax/chart_data.rb
hyrax-3.4.1 app/values/hyrax/chart_data.rb
hyrax-3.4.0 app/values/hyrax/chart_data.rb
hyrax-3.3.0 app/values/hyrax/chart_data.rb
hyrax-3.2.0 app/values/hyrax/chart_data.rb
hyrax-3.1.0 app/values/hyrax/chart_data.rb
hyrax-3.0.2 app/values/hyrax/chart_data.rb