Sha256: b27eee024a7f3d3c0f9aa1daeba9b6ad5939440bfc1e148b772d4f4aa1a1cc81

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

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

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

    def to_h
      @settings
    end

    def initialize(hash = {})
      @settings = hash.with_indifferent_access
    end

    def function(name, body = nil)
      ChartBuilder::Function.new(name, body)
    end

    def literal(name)
      ChartBuilder::Literal.new(name)
    end

    def method_missing(name, *args, &block)
      if block_given?
        @settings[name] = block.call(*args)
      elsif name.to_s.end_with?('=') && 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

2 entries across 2 versions & 1 rubygems

Version Path
amcharts.rb-3.11.2.17 lib/amcharts/settings.rb
amcharts.rb-3.11.2.16 lib/amcharts/settings.rb