Sha256: 43f8c2f09bd106ee430573140fe84b46170e5ad142315b92fbcf1f2116a55329

Contents?: true

Size: 849 Bytes

Versions: 4

Compression:

Stored size: 849 Bytes

Contents

require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/hash/indifferent_access'

module AmCharts
  class Settings
    delegate :[], :each, :fetch, to: :@settings

    def initialize
      @settings = {}.with_indifferent_access
    end

    def function(name)
      ChartBuilder::Function.new(name)
    end

    def method_missing(name, *args, &block)
      if block_given?
        @settings[name] = block.call(*args)
      elsif name.to_s.end_with?('=') and args.length == 1
        prefix = name.to_s.gsub(/=\z/, '')
        @settings[prefix] = args.first
      elsif !args.empty?
        @settings[name] = args.length == 1 ? args.first : args
      elsif name.to_s.end_with?('?')
        prefix = name.to_s.gsub(/\?\z/, '')
        @settings.key?(prefix)
      else
        @settings[name]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
amcharts.rb-3.2.0.0 lib/amcharts/settings.rb
amcharts.rb-3.1.1.3 lib/amcharts/settings.rb
amcharts.rb-3.1.1.1 lib/amcharts/settings.rb
amcharts.rb-3.1.1.0 lib/amcharts/settings.rb