module WhirledPeas::Settings::ThemeLibrary

Constants

CONFIG_FILE

Public Class Methods

add(name, theme) click to toggle source
# File lib/whirled_peas/settings/theme_library.rb, line 15
def add(name, theme)
  themes[name] = theme
end
default_name() click to toggle source
# File lib/whirled_peas/settings/theme_library.rb, line 27
def default_name
  themes.keys.first
end
get(name) click to toggle source
# File lib/whirled_peas/settings/theme_library.rb, line 19
def get(name)
  unless themes.key?(name)
    expected = themes.keys.map(&:inspect).join(', ')
    raise ArgumentError, "Unknown theme: #{name.inspect}, expecting one of #{expected}"
  end
  themes[name]
end
theme_names() click to toggle source
# File lib/whirled_peas/settings/theme_library.rb, line 11
def theme_names
  themes.keys
end

Private Class Methods

themes() click to toggle source
# File lib/whirled_peas/settings/theme_library.rb, line 33
def themes
  return @themes if @themes
  @themes = {}
  config = YAML.load_file(CONFIG_FILE)
  config.each do |name, settings|
    name = name.to_sym
    theme = Theme.new
    settings.each do |key, value|
      case key
      when 'axis_color'
        theme.axis_color = value
      when 'bg_color'
        theme.bg_color = value
      when 'border_color'
        theme.border_color = value
      when 'border_style'
        theme.border_style = value
      when 'color'
        theme.color = value
      when 'highlight_bg_color'
        theme.highlight_bg_color = value
      when 'highlight_color'
        theme.highlight_color = value
      when 'title_font'
        theme.title_font = value
      else
        raise ArgumentError, "Unexpected theme setting: #{key} in #{CONFIG_FILE}"
      end
    end
    @themes[name] = theme
  end
  @themes
end