Sha256: f80a1f47f27bc27bbf12ba3e7ec0d98a91324e6b22639bf9c5dbbf48c2a78655

Contents?: true

Size: 978 Bytes

Versions: 4

Compression:

Stored size: 978 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)
      ChartBuilder::Function.new(name)
    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?('=') 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.4.7.4 lib/amcharts/settings.rb
amcharts.rb-3.4.7.3 lib/amcharts/settings.rb
amcharts.rb-3.4.7.2 lib/amcharts/settings.rb
amcharts.rb-3.4.7.1 lib/amcharts/settings.rb