Class: IStats::Settings
- Inherits:
-
Object
- Object
- IStats::Settings
- Defined in:
- lib/iStats/settings.rb
Class Method Summary collapse
- .addSensor(key, sensors) ⇒ Object
- .configFileExists ⇒ Object
- .delegate(stat) ⇒ Object
- .list ⇒ Object
- .load ⇒ Object
- .set(key, value) ⇒ Object
- .toggleAll(value) ⇒ Object
Class Method Details
.addSensor(key, sensors) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/iStats/settings.rb', line 49 def addSensor(key,sensors) settings = ParseConfig.new(@configDir + @configFile) settings.add(key,sensors) file = File.open(@configDir + @configFile,'w') settings.write(file) file.close end |
.configFileExists ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/iStats/settings.rb', line 36 def configFileExists if File.exist?(@configDir + @configFile) $config = ParseConfig.new(@configDir + @configFile) else puts "No config file #{@configDir}#{@configFile} found .. Run scan" if !File.exist?(@configDir) Dir.mkdir( @configDir) end file=File.open(@configDir + @configFile,"w+") file.close end end |
.delegate(stat) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/iStats/settings.rb', line 9 def delegate(stat) case stat[0] when 'enable' if (stat[1] == 'all') toggleAll("1") else set(stat[1], "1") end when 'disable' if (stat[1] == 'all') toggleAll("0") else set(stat[1], "0") end else puts "Unknown command" end end |
.list ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/iStats/settings.rb', line 87 def list if File.exist?(@configDir + @configFile) settings = ParseConfig.new(@configDir + @configFile) settings.params.keys.each{ |key| if (settings[key]['enabled']) puts key + " => " + SMC.name(key) + " Enabled = " + settings[key]['enabled'] end } else puts "Run 'istats scan' first" end end |
.load ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/iStats/settings.rb', line 28 def load if File.exist?(@configDir + @configFile) $config = ParseConfig.new(@configDir + @configFile) else $config = ParseConfig.new end end |
.set(key, value) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/iStats/settings.rb', line 57 def set(key,value) configFileExists settings = ParseConfig.new(@configDir + @configFile) sensors =settings.params if (sensors[key]) sensors[key]['enabled'] = value else puts "Not valid key" end file = File.open(@configDir + @configFile,'w') settings.write(file) file.close end |
.toggleAll(value) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/iStats/settings.rb', line 71 def toggleAll(value) if File.exist?(@configDir + @configFile) settings = ParseConfig.new(@configDir + @configFile) settings.params.keys.each{ |key| if (settings.params[key]['enabled']) settings.params[key]['enabled'] = value end } file = File.open(@configDir + @configFile,'w') settings.write(file) file.close else puts "Run 'istats scan' first" end end |