Sha256: 794a4226423038cd40aa81cd3ff7e0f22f4f5b4ef24e252d6bf3c1d99ff2e776

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

module CurationConcerns
  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

13 entries across 13 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.7 app/values/curation_concerns/chart_data.rb
curation_concerns-2.0.0 app/values/curation_concerns/chart_data.rb
curation_concerns-2.0.0.rc2 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.6 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.5 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.4 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.3 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.2 app/values/curation_concerns/chart_data.rb
curation_concerns-2.0.0.rc1 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.1 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.0 app/values/curation_concerns/chart_data.rb
curation_concerns-1.7.0.beta1 app/values/curation_concerns/chart_data.rb