20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/co2-notify/config.rb', line 20
def self.set
FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
data = {}.tap do |h|
print "Monitor location (required): "
h["location"] = STDIN.gets.chomp
print "Monitor user (required): "
h["user"] = STDIN.gets.chomp
print "Hipchat API token (required): "
h["api_token"] = STDIN.gets.chomp
print "Hipchat room name (required): "
h["room"] = STDIN.gets.chomp
print "Timeout (default: #{DEFAULT_TIMEOUT} mins): "
h["timeout"] = (STDIN.gets.chomp.presence || DEFAULT_TIMEOUT).to_i
print "Cooldown (default: #{DEFAULT_COOLDOWN} mins): "
h["cooldown"] = (STDIN.gets.chomp.presence || DEFAULT_COOLDOWN).to_i
print "Ping timeout (default: #{DEFAULT_PING_TIMEOUT} mins): "
h["ping_timeout"] = (STDIN.gets.chomp.presence || DEFAULT_PING_TIMEOUT).to_i
print "High CO₂ level (default: #{DEFAULT_HIGH_LEVEL}): "
h["high_level"] = (STDIN.gets.chomp.presence || DEFAULT_HIGH_LEVEL).to_i
print "Very High CO₂ level (default: #{DEFAULT_VERY_HIGH_LEVEL}): "
h["very_high_level"] = (STDIN.gets.chomp.presence || DEFAULT_VERY_HIGH_LEVEL).to_i
print "Start time (default: #{DEFAULT_START_TIME}): "
h["start_time"] = STDIN.gets.chomp.presence || DEFAULT_START_TIME
print "Stop time (default: #{DEFAULT_STOP_TIME}): "
h["stop_time"] = STDIN.gets.chomp.presence || DEFAULT_STOP_TIME
print "Mention (optional): "
h["mention"] = STDIN.gets.chomp
end
File.open(config_file, "w") do |f|
YAML.dump(data, f)
end
end
|