-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.rb
50 lines (42 loc) · 1.06 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
class Configuration
def self.read_config
configHash = {}
config = self.get_config_file
if File.exists?(config)
f = File.open(config)
begin
while (line = f.readline)
configHash = self.readline_into_hash(configHash, line)
end
rescue EOFError
f.close
end
end
configHash = self.set_defaults(configHash)
configHash = self.convert_string_to_int(configHash)
configHash
end
def self.get_config_file
config = File.expand_path(File.join(File.dirname(__FILE__), 'config.app'))
end
def self.readline_into_hash(hash, line)
pair = line.split(':')
if pair.size > 0
hash[pair[0].strip] = pair[1].strip;
end
hash
end
def self.set_defaults(hash)
if not hash.has_key? 'number_to_tweet'
hash['number_to_tweet'] = -1
end
if not hash.has_key? 'testing'
hash['testing'] = false
end
hash
end
def self.convert_string_to_int(hash)
hash['number_to_tweet'] = hash['number_to_tweet'].to_i
hash
end
end