Sha256: d2fc5063b32fa9dccd9e69848a357af50736447891049d06788feabf0239323f

Contents?: true

Size: 584 Bytes

Versions: 14

Compression:

Stored size: 584 Bytes

Contents

# for both multiple series and
# making sure hash order is preserved in JavaScript
module Enumerable
  def chart_json
    if is_a?(Hash)
      if (key = keys.first) && key.is_a?(Array) && key.size == 2
        group_by { |k, _v| k[0] }.map do |name, data|
          {name: name, data: data.map { |k, v| [k[1], v] }}
        end
      else
        to_a
      end
    elsif is_a?(Array)
      map do |v|
        if v.is_a?(Hash) && v[:data].is_a?(Hash)
          v = v.dup
          v[:data] = v[:data].to_a
        end
        v
      end
    else
      self
    end.to_json
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
chartkick-4.2.1 lib/chartkick/enumerable.rb
chartkick-4.2.0 lib/chartkick/enumerable.rb
chartkick-4.1.3 lib/chartkick/enumerable.rb
chartkick-4.1.2 lib/chartkick/enumerable.rb
chartkick-4.1.1 lib/chartkick/enumerable.rb
chartkick-4.1.0 lib/chartkick/enumerable.rb
chartkick-4.0.5 lib/chartkick/enumerable.rb
chartkick-4.0.4 lib/chartkick/enumerable.rb
chartkick-4.0.3 lib/chartkick/enumerable.rb
chartkick-4.0.2 lib/chartkick/enumerable.rb
chartkick-4.0.1 lib/chartkick/enumerable.rb
chartkick-4.0.0 lib/chartkick/enumerable.rb
chartkick-3.4.2 lib/chartkick/enumerable.rb
chartkick-3.4.1 lib/chartkick/enumerable.rb