Class: GoogleChart::AbstractChart

Inherits:
Object
  • Object
show all
Defined in:
lib/google_chart/abstract_chart.rb

Direct Known Subclasses

BarChart, LineChart

Constant Summary collapse

@@base_url =
'http://chart.apis.google.com/chart'
@@default_size =
'600x500'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ AbstractChart

Returns a new instance of AbstractChart.

Yields:

  • (_self)

Yield Parameters:



6
7
8
9
# File 'lib/google_chart/abstract_chart.rb', line 6

def initialize(options = {})
  options.each {|key, value| send("#{key}=", value) }
  yield self if block_given?
end

Instance Attribute Details

#sizeObject



17
18
19
20
# File 'lib/google_chart/abstract_chart.rb', line 17

def size
  @size ||= @@default_size
  "chs=#{@size}"
end

Class Method Details

.inherited(klass) ⇒ Object



22
23
24
25
26
27
# File 'lib/google_chart/abstract_chart.rb', line 22

def self.inherited(klass)
  klass.class_eval do
    class_variable_set(:@@parameters, [])
    register!(:chart_type, :size)
  end
end

.register!(*parameters) ⇒ Object



29
30
31
32
33
# File 'lib/google_chart/abstract_chart.rb', line 29

def self.register!(*parameters)
  parameters.each do |parameter|
    registry.push(parameter) unless registered?(parameter)
  end
end

.registered?(parameter) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/google_chart/abstract_chart.rb', line 35

def self.registered?(parameter)
  registry.include?(parameter)
end

.registryObject



39
40
41
# File 'lib/google_chart/abstract_chart.rb', line 39

def self.registry
  class_variable_get :@@parameters
end

Instance Method Details

#to_urlObject



11
12
13
# File 'lib/google_chart/abstract_chart.rb', line 11

def to_url
  "#{@@base_url}?#{query_string}"
end