iniparser 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6681fa0238b38ea834fdc8452d8da9bc1233996f
4
- data.tar.gz: 70f3ef1fd66d4692bd2087fed4004f8788839047
3
+ metadata.gz: 864d2c269a38ca9efb21af2a1e8710c963edf9dc
4
+ data.tar.gz: 94e3fcd5157e7e8ab9a86e4be678e1eb5250d3d7
5
5
  SHA512:
6
- metadata.gz: b4e304e2f6d4fac81144565b4c3d265767ec5a672a040f8fa7eac0262cf89b6242fe66e69e86522c2854bff531974d4319333fe10346093c95cfdc9653453c3c
7
- data.tar.gz: 4559486a9a9dc64f0f4312ee9664ca54b70bb7358cc1c09b3b8f250825e132e329e3ec5b3ae17afa4b21dfecc657038e8a0daf3af0cd9c02f02933c3f05c2a91
6
+ metadata.gz: 6b481907b4e2aac189c6a9fb12460ae8c5a7c0e286b822d68350a70465e53dc64e37e8743537d4a5e45b5a6aa330114ba8fe0ff2d8cabbaf51992b38782bb9a1
7
+ data.tar.gz: f6a5abb22e3baa710f7f3b4ffdab56957dbd1163bd8187bb24e61e0c0f1522345ea1f46b9f3f1d29f454d60895e9ee33bfea332489dfd71a4a906635620ef79f
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # iniparser - read / parse INI configuration, settings and data files into a hash
1
+ # iniparser - read / parse INI configuration, settings and data files into a hash (incl. named subsections)
2
2
 
3
3
 
4
4
  * home :: [github.com/datatxt/iniparser](https://github.com/datatxt/iniparser)
@@ -168,7 +168,7 @@ file=payroll.dat
168
168
 
169
169
  resulting in:
170
170
 
171
- ```
171
+ ``` ruby
172
172
  {"owner"=>{"name"=>"John Doe", "organization"=>"Acme Widgets Inc."},
173
173
  "database"=>{"server"=>"192.0.2.62", "port"=>"143", "file"=>"payroll.dat"}}
174
174
  ```
@@ -217,6 +217,49 @@ resulting in:
217
217
  "location"=>"Krak\u00F3w \u203A Poland"}}
218
218
  ```
219
219
 
220
+ **Rosetta Stone - Read A Configuration File**
221
+
222
+ ```
223
+ # This is a configuration file in standard configuration file format
224
+ #
225
+ # Lines beginning with a hash or a semicolon are ignored by the application
226
+ # program. Blank lines are also ignored by the application program.
227
+
228
+ # This is the fullname parameter
229
+ FULLNAME Foo Barber
230
+
231
+ # This is a favourite fruit
232
+ FAVOURITEFRUIT banana
233
+
234
+ # This is a boolean that should be set
235
+ NEEDSPEELING
236
+
237
+ # This boolean is commented out
238
+ ; SEEDSREMOVED
239
+
240
+ # Configuration option names are not case sensitive, but configuration parameter
241
+ # data is case sensitive and may be preserved by the application program.
242
+
243
+ # An optional equals sign can be used to separate configuration parameter data
244
+ # from the option name. This is dropped by the parser.
245
+
246
+ # A configuration option may take multiple parameters separated by commas.
247
+ # Leading and trailing whitespace around parameter names and parameter data fields
248
+ # are ignored by the application program.
249
+
250
+ OTHERFAMILY Rhu Barber, Harry Barber
251
+ ```
252
+
253
+ resulting in:
254
+
255
+ ``` ruby
256
+ {"FULLNAME"=>"Foo Barber",
257
+ "FAVOURITEFRUIT"=>"banana",
258
+ "NEEDSPEELING"=>"",
259
+ "OTHERFAMILY"=>"Rhu Barber, Harry Barber"}
260
+ ```
261
+
262
+
220
263
 
221
264
  ## Frequently Asked Questions (FAQ) and Answers
222
265
 
@@ -284,7 +327,7 @@ and NOT resulting in:
284
327
  ``` ruby
285
328
  {"http"=>
286
329
  {"https://weak.example.com"=>
287
- {"sslVerify"=>"false", "cookieFile"=>"/tmp/cookie.txt"}}}
330
+ {"sslVerify"=>false, "cookieFile"=>"/tmp/cookie.txt"}}}
288
331
  ```
289
332
 
290
333
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ Hoe.spec 'iniparser' do
5
5
 
6
6
  self.version = IniParser::VERSION
7
7
 
8
- self.summary = 'iniparser - read / parse INI configuration, settings and data files into a hash'
8
+ self.summary = 'iniparser - read / parse INI configuration, settings and data files into a hash (incl. named subsections)'
9
9
  self.description = summary
10
10
 
11
11
  self.urls = ['https://github.com/datatxt/iniparser']
@@ -41,7 +41,9 @@ module IniParser
41
41
 
42
42
  COMMENT_CLASS = '[#;]' # note: for now support # and ; - why? why not?
43
43
 
44
- SEP_CLASS = '[=]' # note: name/value separator - for now only support = (no longer support :) - why? why not?
44
+ SEP_CLASS = '[= ]' # note: name/value separator
45
+ # - for now support = AND yes, space!!
46
+ # (note: no longer support :) - why? why not?
45
47
 
46
48
 
47
49
  # note: for now do NOT support dot (.) - keep reserved for hierarchy latter
@@ -3,7 +3,7 @@
3
3
  module IniParser
4
4
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
5
5
  MINOR = 0
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
@@ -31,11 +31,21 @@ class TestParser < MiniTest::Test
31
31
  # comment here
32
32
  title = A rose is a rose is a rose, eh?
33
33
  ; another comment here
34
- title2 = A rose is a rose is a rose, eh?
34
+ title2 = A rose is a rose is a rose, eh?
35
35
  TXT
36
36
 
37
37
  hash = INI.load( text )
38
- pp hash
38
+
39
+ exp = {"key1"=>"hello",
40
+ "key2"=>"hi!",
41
+ "section1"=>{"key3"=>"salut"},
42
+ "section2"=>{"key4"=>"hola", "blank"=>"", "blank2"=>""},
43
+ "section3"=>
44
+ {"http://example.com"=>
45
+ {"title"=>"A rose is a rose is a rose, eh?",
46
+ "title2"=>"A rose is a rose is a rose, eh?"}}}
47
+
48
+ assert_equal exp, hash
39
49
 
40
50
  assert_equal 'hello', hash['key1']
41
51
  assert_equal 'hi!', hash['key2']
@@ -54,22 +64,22 @@ TXT
54
64
  # a '#' or ';' character indicates
55
65
  # a comment
56
66
  #
57
-
67
+
58
68
  ; core variables
59
69
  [core]
60
70
  ; Don't trust file modes
61
71
  filemode = false
62
-
72
+
63
73
  ; Our diff algorithm
64
74
  [diff]
65
75
  external = /usr/local/bin/diff-wrapper
66
76
  renames = true
67
-
77
+
68
78
  ; Proxy settings
69
79
  [core]
70
80
  gitproxy=proxy-command for kernel.org
71
81
  gitproxy=default-proxy ; for all the rest
72
-
82
+
73
83
  ; HTTP
74
84
  [http]
75
85
  sslVerify
@@ -79,41 +89,64 @@ TXT
79
89
  TXT
80
90
 
81
91
  hash = INI.load( text )
82
- pp hash
83
92
 
93
+ exp = {"core"=>{"filemode"=>"false", "gitproxy"=>"default-proxy"},
94
+ "diff"=>{"external"=>"/usr/local/bin/diff-wrapper", "renames"=>"true"},
95
+ "http"=>
96
+ {"sslVerify"=>"",
97
+ "https://weak.example.com"=>
98
+ {"sslVerify"=>"false", "cookieFile"=>"/tmp/cookie.txt"}}}
99
+
100
+ assert_equal exp, hash
84
101
 
85
102
  assert_equal 'default-proxy', hash['core']['gitproxy']
86
103
 
87
104
  assert_equal '', hash['http']['sslVerify']
88
- assert_equal 'false', hash['http']['https://weak.example.com']['sslVerify']
105
+ assert_equal 'false', hash['http']['https://weak.example.com']['sslVerify']
89
106
  end
90
107
 
91
108
  def test_planet
92
109
  text =<<TXT
93
110
  title = Planet Ruby
94
-
111
+
95
112
  [Ruby Lang News]
96
113
  feed = http://www.ruby-lang.org/en/feeds/news.rss
97
-
114
+
98
115
  [Rails Girls Summer of Code News]
99
116
  feed = https://railsgirlssummerofcode.org/blog.xml
100
-
101
-
117
+
118
+
102
119
  [Benoit Daloze]
103
120
  feed = https://eregon.me/blog/feed.xml
104
121
  location = Zürich › Switzerland
105
-
122
+
106
123
  [Thomas Leitner]
107
124
  feed = https://gettalong.org/posts.atom
108
125
  location = Vienna • Wien › Austria
109
-
126
+
110
127
  [Paweł Świątkowski]
111
128
  feed = https://rubytuesday.katafrakt.me/feed.xml
112
129
  location = Kraków › Poland
113
130
  TXT
114
131
 
115
132
  hash = INI.load( text )
116
- pp hash
133
+
134
+ exp = {"title"=>"Planet Ruby",
135
+ "Ruby Lang News"=>
136
+ {"feed"=>"http://www.ruby-lang.org/en/feeds/news.rss"},
137
+ "Rails Girls Summer of Code News"=>
138
+ {"feed"=>"https://railsgirlssummerofcode.org/blog.xml"},
139
+ "Benoit Daloze"=>
140
+ {"feed"=>"https://eregon.me/blog/feed.xml",
141
+ "location"=>"Zürich › Switzerland"},
142
+ "Thomas Leitner"=>
143
+ {"feed"=>"https://gettalong.org/posts.atom",
144
+ "location"=>"Vienna • Wien › Austria"},
145
+ "Paweł Świątkowski"=>
146
+ {"feed"=>"https://rubytuesday.katafrakt.me/feed.xml",
147
+ "location"=>"Kraków › Poland"}}
148
+
149
+ assert_equal exp, hash
117
150
 
118
151
  assert_equal 'Kraków › Poland', hash['Paweł Świątkowski']['location']
119
152
  end
@@ -123,22 +156,28 @@ TXT
123
156
  [database "development"]
124
157
  adapter = sqlite3
125
158
  database = db/development.sqlite3
126
-
159
+
127
160
  [database "test"]
128
161
  adapter = sqlite3
129
162
  database = db/test.sqlite3
130
-
163
+
131
164
  [database "production"]
132
165
  adapter = sqlite3
133
166
  database = db/production.sqlite3
134
167
  TXT
135
168
 
136
169
  hash = INI.load( text )
137
- pp hash
170
+
171
+ exp = {"database"=>
172
+ {"development"=>{"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"},
173
+ "test"=>{"adapter"=>"sqlite3", "database"=>"db/test.sqlite3"},
174
+ "production"=>{"adapter"=>"sqlite3", "database"=>"db/production.sqlite3"}}}
175
+
176
+ assert_equal exp, hash
138
177
 
139
178
  assert_equal 'db/development.sqlite3', hash['database']['development']['database']
140
179
  assert_equal 'db/test.sqlite3', hash['database']['test']['database']
141
- end
180
+ end
142
181
 
143
182
  def test_windows
144
183
  text =<<TXT
@@ -146,7 +185,7 @@ TXT
146
185
  [owner]
147
186
  name=John Doe
148
187
  organization=Acme Widgets Inc.
149
-
188
+
150
189
  [database]
151
190
  ; use IP address in case network name resolution is not working
152
191
  server=192.0.2.62
@@ -155,10 +194,14 @@ TXT
155
194
  TXT
156
195
 
157
196
  hash = INI.load( text )
158
- pp hash
197
+
198
+ exp = {"owner"=>{"name"=>"John Doe", "organization"=>"Acme Widgets Inc."},
199
+ "database"=>{"server"=>"192.0.2.62", "port"=>"143", "file"=>"payroll.dat"}}
200
+
201
+ assert_equal exp, hash
159
202
 
160
203
  assert_equal '192.0.2.62', hash['database']['server']
161
- end
204
+ end
162
205
 
163
206
  def test_quick
164
207
  ## from python's configparser
@@ -168,20 +211,71 @@ TXT
168
211
  Compression = yes
169
212
  CompressionLevel = 9
170
213
  ForwardX11 = yes
171
-
214
+
172
215
  [bitbucket.org]
173
216
  User = hg
174
-
217
+
175
218
  [topsecret.server.com]
176
219
  Port = 50022
177
220
  ForwardX11 = no
178
221
  TXT
179
222
 
180
223
  hash = INI.load( text )
181
- pp hash
224
+
225
+ exp = {"DEFAULT"=>
226
+ {"ServerAliveInterval"=>"45",
227
+ "Compression"=>"yes",
228
+ "CompressionLevel"=>"9",
229
+ "ForwardX11"=>"yes"},
230
+ "bitbucket.org"=>{"User"=>"hg"},
231
+ "topsecret.server.com"=>{"Port"=>"50022", "ForwardX11"=>"no"}}
232
+
233
+ assert_equal exp, hash
182
234
 
183
235
  assert_equal 'yes', hash['DEFAULT']['ForwardX11']
184
236
  assert_equal 'hg', hash['bitbucket.org']['User']
185
237
  assert_equal 'no', hash['topsecret.server.com']['ForwardX11']
186
238
  end
239
+
240
+ def test_rosetta_stone
241
+ text =<<TXT
242
+ # This is a configuration file in standard configuration file format
243
+ #
244
+ # Lines beginning with a hash or a semicolon are ignored by the application
245
+ # program. Blank lines are also ignored by the application program.
246
+
247
+ # This is the fullname parameter
248
+ FULLNAME Foo Barber
249
+
250
+ # This is a favourite fruit
251
+ FAVOURITEFRUIT banana
252
+
253
+ # This is a boolean that should be set
254
+ NEEDSPEELING
255
+
256
+ # This boolean is commented out
257
+ ; SEEDSREMOVED
258
+
259
+ # Configuration option names are not case sensitive, but configuration parameter
260
+ # data is case sensitive and may be preserved by the application program.
261
+
262
+ # An optional equals sign can be used to separate configuration parameter data
263
+ # from the option name. This is dropped by the parser.
264
+
265
+ # A configuration option may take multiple parameters separated by commas.
266
+ # Leading and trailing whitespace around parameter names and parameter data fields
267
+ # are ignored by the application program.
268
+
269
+ OTHERFAMILY Rhu Barber, Harry Barber
270
+ TXT
271
+
272
+ hash = INI.load( text )
273
+
274
+ exp = {"FULLNAME"=>"Foo Barber",
275
+ "FAVOURITEFRUIT"=>"banana",
276
+ "NEEDSPEELING"=>"",
277
+ "OTHERFAMILY"=>"Rhu Barber, Harry Barber"}
278
+
279
+ assert_equal exp, hash
280
+ end
187
281
  end # class TestParser
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iniparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-23 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.16'
41
41
  description: iniparser - read / parse INI configuration, settings and data files into
42
- a hash
42
+ a hash (incl. named subsections)
43
43
  email: ruby-talk@ruby-lang.org
44
44
  executables: []
45
45
  extensions: []
@@ -85,5 +85,5 @@ rubygems_version: 2.5.2
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: iniparser - read / parse INI configuration, settings and data files into
88
- a hash
88
+ a hash (incl. named subsections)
89
89
  test_files: []