Class: Chart::Theme
- Inherits:
-
Object
- Object
- Chart::Theme
- Defined in:
- lib/gchart/theme.rb
Defined Under Namespace
Classes: ThemeNotFound
Constant Summary collapse
- @@theme_files =
["#{File.dirname(__FILE__)}/../themes.yml"]
Instance Attribute Summary collapse
-
#background ⇒ Object
Returns the value of attribute background.
-
#bar_colors ⇒ Object
Returns the value of attribute bar_colors.
-
#chart_background ⇒ Object
Returns the value of attribute chart_background.
-
#colors ⇒ Object
Returns the value of attribute colors.
Class Method Summary collapse
-
.add_theme_file(file) ⇒ Object
Allows you to specify paths for custom theme files in YAML format.
- .load(theme_name) ⇒ Object
- .theme_files ⇒ Object
Instance Method Summary collapse
-
#initialize(theme_name) ⇒ Theme
constructor
A new instance of Theme.
- #to_options ⇒ Object
Constructor Details
#initialize(theme_name) ⇒ Theme
Returns a new instance of Theme.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gchart/theme.rb', line 27 def initialize(theme_name) themes = {} @@theme_files.each {|f| themes.update YAML::load(File.open(f))} theme = themes[theme_name] if theme self.colors = theme[:colors] self. = theme[:bar_colors] self.background = theme[:background] self.chart_background = theme[:chart_background] self else raise(ThemeNotFound, "Could not locate the #{theme_name} theme ...") end end |
Instance Attribute Details
#background ⇒ Object
Returns the value of attribute background.
11 12 13 |
# File 'lib/gchart/theme.rb', line 11 def background @background end |
#bar_colors ⇒ Object
Returns the value of attribute bar_colors.
10 11 12 |
# File 'lib/gchart/theme.rb', line 10 def @bar_colors end |
#chart_background ⇒ Object
Returns the value of attribute chart_background.
12 13 14 |
# File 'lib/gchart/theme.rb', line 12 def chart_background @chart_background end |
#colors ⇒ Object
Returns the value of attribute colors.
9 10 11 |
# File 'lib/gchart/theme.rb', line 9 def colors @colors end |
Class Method Details
.add_theme_file(file) ⇒ Object
Allows you to specify paths for custom theme files in YAML format
23 24 25 |
# File 'lib/gchart/theme.rb', line 23 def self.add_theme_file(file) @@theme_files << file end |
.load(theme_name) ⇒ Object
14 15 16 |
# File 'lib/gchart/theme.rb', line 14 def self.load(theme_name) theme = new(theme_name) end |
.theme_files ⇒ Object
18 19 20 |
# File 'lib/gchart/theme.rb', line 18 def self.theme_files @@theme_files end |
Instance Method Details
#to_options ⇒ Object
42 43 44 |
# File 'lib/gchart/theme.rb', line 42 def {:background => background, :chart_background => chart_background, :bar_colors => .join(',')} end |