Class: Tco::Config
- Inherits:
-
Object
- Object
- Tco::Config
- Defined in:
- lib/tco/config.rb
Instance Attribute Summary collapse
-
#colour_values ⇒ Object
Returns the value of attribute colour_values.
-
#names ⇒ Object
Returns the value of attribute names.
-
#options ⇒ Object
Returns the value of attribute options.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
-
#initialize(locations = []) ⇒ Config
constructor
A new instance of Config.
- #load(path) ⇒ Object
Constructor Details
#initialize(locations = []) ⇒ Config
Returns a new instance of Config.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tco/config.rb', line 30 def initialize(locations=[]) @options = { "palette" => "extended", "output" => "term", "disabled" => false } @colour_values = {} @names = { "black" => "@0", "red" => "@1", "green" => "@2", "yellow" => "@3", "blue" => "@4", "magenta" => "@5", "cyan" => "@6", "light-grey" => "@7", "grey" => "@8", "light-red" => "@9", "light-green" => "@10", "light-yellow" => "@11", "light-blue" => "@12", "light-magenta" => "@13", "light-cyan" => "@14", "white" => "@15" } @styles = {} locations.each do |conf_file| conf_file = File. conf_file next unless File.exists? conf_file load conf_file end end |
Instance Attribute Details
#colour_values ⇒ Object
Returns the value of attribute colour_values.
28 29 30 |
# File 'lib/tco/config.rb', line 28 def colour_values @colour_values end |
#names ⇒ Object
Returns the value of attribute names.
28 29 30 |
# File 'lib/tco/config.rb', line 28 def names @names end |
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/tco/config.rb', line 28 def @options end |
#styles ⇒ Object
Returns the value of attribute styles.
28 29 30 |
# File 'lib/tco/config.rb', line 28 def styles @styles end |
Instance Method Details
#load(path) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tco/config.rb', line 65 def load(path) conf_file = YAML::load_file path if conf_file.has_key? "options" if conf_file["options"].is_a? Hash conf_file["options"].each do |id, value| @options[id] = case id when "disabled" then parse_bool value else value end end else raise "The 'options' config option must be a hash." end end if conf_file.has_key? "colour_values" if conf_file["colour_values"].is_a? Hash conf_file["colour_values"].each do |id, value| @colour_values[id] = value end else raise "The 'colour_values' config option must be a hash." end end if conf_file.has_key? "names" if conf_file["names"].is_a? Hash conf_file["names"].each do |name, colour| @names[name] = colour end else raise "Invalid format of the 'names' option." end end if conf_file.has_key? "styles" if conf_file["styles"].is_a? Hash conf_file["styles"].each do |name, styledef| style = {:fg => nil, :bg => nil, :bright => false, :underline => false} if styledef.has_key? "fg" style[:fg] = styledef["fg"] end if styledef.has_key? "bg" style[:bg] = styledef["bg"] end if styledef.has_key? "bright" style[:bright] = parse_bool styledef["bright"] end if styledef.has_key? "underline" style[:underline] = parse_bool styledef["underline"] end @styles[name] = style end else raise "Invalid format of the 'styles' option." end end end |