inireader 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/inireader-0.0.1.gem +0 -0
- data/lib/ini_reader.rb +1 -1
- data/lib/inireader/base.rb +30 -32
- data/lib/inireader/version.rb +2 -2
- data/spec/ini_reader_spec.rb +1 -1
- data/spec/inireader/base_spec.rb +15 -15
- metadata +2 -1
data/inireader-0.0.1.gem
ADDED
Binary file
|
data/lib/ini_reader.rb
CHANGED
data/lib/inireader/base.rb
CHANGED
@@ -1,39 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
class IniReader
|
2
|
+
def initialize( string = '')
|
3
|
+
@section_hash = {}
|
4
|
+
parse(StringIO.new(string))
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def self.parse(filename)
|
8
|
+
reader = IniReader.new
|
9
|
+
reader.send(:parse, File.open(filename, "r"))
|
10
|
+
return reader
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
#returns the hash for a section of the inifile
|
14
|
+
def []( section_name )
|
15
|
+
return @section_hash[section_name]
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
private
|
19
|
+
def parse(io)
|
20
|
+
current_section = nil
|
21
|
+
io.each do |line|
|
22
|
+
line = line.strip
|
23
|
+
if line[0] == ';'
|
24
|
+
next
|
25
|
+
elsif ( matchdata = line.match(/^\[(.+)\]$/) ) != nil
|
26
|
+
current_section = @section_hash[matchdata[1].to_sym] || {}
|
27
|
+
@section_hash[matchdata[1].to_sym] = current_section
|
28
|
+
elsif ( matchdata = line.match(/^([^=]*)=(.*)$/) )
|
29
|
+
current_section[matchdata[1].to_sym] = matchdata[2].to_s
|
30
|
+
elsif line.strip == ""
|
31
|
+
next
|
32
|
+
else
|
33
|
+
raise Exception("Could not parse line: #{line}")
|
35
34
|
end
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
data/lib/inireader/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class IniReader
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|
data/spec/ini_reader_spec.rb
CHANGED
data/spec/inireader/base_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
describe IniReader
|
1
|
+
describe IniReader do
|
2
2
|
it "should exist" do
|
3
3
|
lambda do
|
4
|
-
reader = IniReader
|
4
|
+
reader = IniReader.new
|
5
5
|
end.should_not raise_error
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should return nil if looking for a section that doesn't exist" do
|
9
|
-
reader = IniReader
|
9
|
+
reader = IniReader.new
|
10
10
|
reader[:section_name].should == nil
|
11
11
|
end
|
12
12
|
|
@@ -15,7 +15,7 @@ describe IniReader::Base do
|
|
15
15
|
"blah blah blah\n" +
|
16
16
|
"key1=val1\n"
|
17
17
|
lambda do
|
18
|
-
reader = IniReader
|
18
|
+
reader = IniReader.new(section_string)
|
19
19
|
end.should raise_error
|
20
20
|
end
|
21
21
|
|
@@ -24,7 +24,7 @@ describe IniReader::Base do
|
|
24
24
|
";blah blah blah\n" +
|
25
25
|
"key1=val1\n"
|
26
26
|
lambda do
|
27
|
-
reader = IniReader
|
27
|
+
reader = IniReader.new(section_string)
|
28
28
|
end.should_not raise_error
|
29
29
|
end
|
30
30
|
|
@@ -33,21 +33,21 @@ describe IniReader::Base do
|
|
33
33
|
"\n" +
|
34
34
|
"key1=val1\n"
|
35
35
|
lambda do
|
36
|
-
reader = IniReader
|
36
|
+
reader = IniReader.new(section_string)
|
37
37
|
end.should_not raise_error
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "sections" do
|
41
41
|
it "should add a section when it sees a section header" do
|
42
42
|
section_string = "[section_name]\n"
|
43
|
-
reader = IniReader
|
43
|
+
reader = IniReader.new(section_string)
|
44
44
|
reader[:section_name].should_not == nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should allow for different section names" do
|
48
48
|
section_string = "[section_name]\n" +
|
49
49
|
"[section_name_2]\n"
|
50
|
-
reader = IniReader
|
50
|
+
reader = IniReader.new(section_string)
|
51
51
|
reader[:section_name].should_not == nil
|
52
52
|
reader[:section_name_2].should_not == nil
|
53
53
|
end
|
@@ -55,7 +55,7 @@ describe IniReader::Base do
|
|
55
55
|
it "should force the section to have a name" do
|
56
56
|
section_string = "[]\n"
|
57
57
|
lambda do
|
58
|
-
reader = IniReader
|
58
|
+
reader = IniReader.new(section_string)
|
59
59
|
end.should raise_error
|
60
60
|
end
|
61
61
|
end
|
@@ -65,14 +65,14 @@ describe IniReader::Base do
|
|
65
65
|
section_string = "[section_name]\n" +
|
66
66
|
"key1=val1\n"
|
67
67
|
lambda do
|
68
|
-
reader = IniReader
|
68
|
+
reader = IniReader.new(section_string)
|
69
69
|
end.should_not raise_error
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should add a pair to the associated section" do
|
73
73
|
section_string = "[section_name]\n" +
|
74
74
|
"key1=val1\n"
|
75
|
-
reader = IniReader
|
75
|
+
reader = IniReader.new(section_string)
|
76
76
|
reader[:section_name].class.should == Hash
|
77
77
|
reader[:section_name][:key1].should == "val1"
|
78
78
|
end
|
@@ -81,7 +81,7 @@ describe IniReader::Base do
|
|
81
81
|
section_string = "[section_name]\n" +
|
82
82
|
"[section_name2]\n" +
|
83
83
|
"key1=val1\n"
|
84
|
-
reader = IniReader
|
84
|
+
reader = IniReader.new(section_string)
|
85
85
|
reader[:section_name][:key1].should == nil
|
86
86
|
end
|
87
87
|
|
@@ -90,7 +90,7 @@ describe IniReader::Base do
|
|
90
90
|
"key1=val1\n" +
|
91
91
|
"[section_name]\n" +
|
92
92
|
"key3=val3\n"
|
93
|
-
reader = IniReader
|
93
|
+
reader = IniReader.new(section_string)
|
94
94
|
reader[:section_name][:key3].should == "val3"
|
95
95
|
end
|
96
96
|
|
@@ -99,7 +99,7 @@ describe IniReader::Base do
|
|
99
99
|
"key1=val1\n" +
|
100
100
|
"[section_name]\n" +
|
101
101
|
"key3=val3\n"
|
102
|
-
reader = IniReader
|
102
|
+
reader = IniReader.new(section_string)
|
103
103
|
reader[:section_name][:key1].should == "val1"
|
104
104
|
end
|
105
105
|
end
|
@@ -117,7 +117,7 @@ describe IniReader::Base do
|
|
117
117
|
outfile = File.new("./string", "w")
|
118
118
|
outfile.write(string)
|
119
119
|
outfile.close
|
120
|
-
reader = IniReader
|
120
|
+
reader = IniReader.parse("./string")
|
121
121
|
reader[:section].should == {key1: "val3", key2: "val2"}
|
122
122
|
reader[:section2].should == {key1:"key2=val1", key3:"val2"}
|
123
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inireader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- Gemfile
|
104
104
|
- README.md
|
105
105
|
- Rakefile
|
106
|
+
- inireader-0.0.1.gem
|
106
107
|
- inireader.gemspec
|
107
108
|
- lib/ini_reader.rb
|
108
109
|
- lib/inireader/base.rb
|