Sha256: c82f0e3ed4d7bbd093367816b316dda75203e105027047fab7415bb7961cfd76

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

require "chartkickm/helper"
require "chartkickm/version"

# integrations
require "chartkickm/engine" if defined?(Rails)
require "chartkickm/sinatra" if defined?(Sinatra)

if defined?(ActiveSupport.on_load)
  ActiveSupport.on_load(:action_view) do
    include Chartkickm::Helper
  end
end

module Chartkickm
  class << self
    attr_accessor :content_for
    attr_accessor :options
  end
  self.options = {}
end

# for multiple series
# use Enumerable so it can be called on arrays
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

2 entries across 2 versions & 1 rubygems

Version Path
chartkickm-3.0.7 lib/chartkickm.rb
chartkickm-3.0.6 lib/chartkickm.rb