Class: AmCharts::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/amcharts/settings.rb

Direct Known Subclasses

DataSource

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Settings

Returns a new instance of Settings.



12
13
14
# File 'lib/amcharts/settings.rb', line 12

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/amcharts/settings.rb', line 24

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

Instance Method Details

#function(name, body = nil) ⇒ Object



16
17
18
# File 'lib/amcharts/settings.rb', line 16

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

#literal(name) ⇒ Object



20
21
22
# File 'lib/amcharts/settings.rb', line 20

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

#to_hObject



8
9
10
# File 'lib/amcharts/settings.rb', line 8

def to_h
  @settings
end