dslh 0.3.0 → 0.3.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: 03bc40c96b4543fc6f64a2c59c7d5232d774e2d8
4
- data.tar.gz: 7de70d4ee2eea8fbf6a3a98c06065b6dbca8c8c6
3
+ metadata.gz: 069a25cadfe07e5fb94b13999c621805b209934f
4
+ data.tar.gz: 61352ba15ae2c64775f6ee6498142cf4343f3004
5
5
  SHA512:
6
- metadata.gz: ae912dc62430f939a902962a34e81ded1d847b2915de51d169bc0413bb60ac48ddb7d975b3f35431a30df3b9f78f9ee6d9761a3aabb1af9af84da75b299eee1a
7
- data.tar.gz: 48b171525b578a2228e0068fa29b77bf6af71570b85231688923b38f4e9e8777b041156ff530f438be8afa21450b5fdd0e05f21addc79b14274d802bde89fb98
6
+ metadata.gz: cee130b7d63b7288c7b4db402117562d290fc1d29dbf9a94a494d7f27d7ef992685df441b8510a050b40b3f3f6db66a9766cc40262d3de617b239895c391acbf
7
+ data.tar.gz: 2d76120513c6ce2b5fdff0236b1c3e4160d548f8523c30d61ed70c623c9611f640a8983b47639150336da8a0d3632fb590237db5ef4d7cd350eb5b7f2ca73437
data/README.md CHANGED
@@ -62,22 +62,22 @@ pp h
62
62
 
63
63
  ```ruby
64
64
  # h =>
65
- {:glossary=>
66
- {:title=>"example glossary",
67
- :GlossDiv=>
68
- {:title=>"S",
69
- :GlossList=>
70
- {:GlossEntry=>
71
- {:ID=>"SGML",
72
- :SortAs=>"SGML",
73
- :GlossTerm=>"Standard Generalized Markup Language",
74
- :Acronym=>"SGML",
75
- :Abbrev=>"ISO 8879:1986",
76
- :GlossDef=>
77
- {:para=>
65
+ {"glossary"=>
66
+ {"title"=>"example glossary",
67
+ "GlossDiv"=>
68
+ {"title"=>"S",
69
+ "GlossList"=>
70
+ {"GlossEntry"=>
71
+ {"ID"=>"SGML",
72
+ "SortAs"=>"SGML",
73
+ "GlossTerm"=>"Standard Generalized Markup Language",
74
+ "Acronym"=>"SGML",
75
+ "Abbrev"=>"ISO 8879:1986",
76
+ "GlossDef"=>
77
+ {"para"=>
78
78
  "A meta-markup language, used to create markup languages such as DocBook.",
79
- :GlossSeeAlso=>["GML", "XML"]},
80
- :GlossSee=>"markup"}}}}}
79
+ "GlossSeeAlso"=>["GML", "XML"]},
80
+ "GlossSee"=>"markup"}}}}}
81
81
  ```
82
82
 
83
83
  ### deval
@@ -39,7 +39,7 @@ class Dslh
39
39
 
40
40
  def initialize(options = {})
41
41
  @options = options.dup
42
- @options[:key_conv] ||= @options[:conv]
42
+ @options[:key_conv] ||= (@options[:conv] || proc {|i| i.to_s })
43
43
  @options[:value_conv] ||= @options[:conv]
44
44
  end
45
45
 
@@ -1,3 +1,3 @@
1
1
  class Dslh
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -19,8 +19,8 @@ describe Dslh do
19
19
  end
20
20
 
21
21
  expect(h).to eq({
22
- :key1 => 'value',
23
- :key2 => 100,
22
+ 'key1' => 'value',
23
+ 'key2' => 100,
24
24
  })
25
25
  end
26
26
 
@@ -46,12 +46,12 @@ describe Dslh do
46
46
  end
47
47
 
48
48
  expect(h).to eq(
49
- {:key1=>"value",
50
- :key2=>100,
51
- :key3=>
52
- {:key31=>{"value31"=>{:key311=>100, :key312=>"200"}},
53
- :key32=>
54
- {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>:XXX}}, :key322=>300}}}
49
+ {'key1'=>"value",
50
+ 'key2'=>100,
51
+ 'key3'=>
52
+ {'key31'=>{"value31"=>{'key311'=>100, 'key312'=>"200"}},
53
+ 'key32'=>
54
+ {'key321'=>{"value321"=>{'key3211'=>"XXX", 'key3212'=>:XXX}}, 'key322'=>300}}}
55
55
  )
56
56
  end
57
57
 
@@ -77,12 +77,12 @@ describe Dslh do
77
77
  end
78
78
 
79
79
  expect(h).to eq(
80
- {:key1=>"value",
81
- :key2=>100,
82
- :key3=>
83
- {:key31=>{:key311=>100, :key312=>"200"},
80
+ {'key1'=>"value",
81
+ 'key2'=>100,
82
+ 'key3'=>
83
+ {'key31'=>{'key311'=>100, 'key312'=>"200"},
84
84
  'key32'=>
85
- {:key321=>{:key3211=>"XXX", :key3212=>:XXX}, :key322=>300}}}
85
+ {'key321'=>{'key3211'=>"XXX", 'key3212'=>:XXX}, 'key322'=>300}}}
86
86
  )
87
87
  end
88
88
 
@@ -108,12 +108,12 @@ describe Dslh do
108
108
  end
109
109
 
110
110
  expect(h).to eq(
111
- {:key1=>"value",
112
- :key2=>100,
113
- :key3=>
114
- {:key31=>{"value31"=>{:key311=>100, :key312=>"200 key3 key31"}},
115
- :key32=>
116
- {:key321=>{"value321"=>{:key3211=>"XXX key3 key32 key321", :key3212=>:XXX}}, :key322=>300}}}
111
+ {'key1'=>"value",
112
+ 'key2'=>100,
113
+ 'key3'=>
114
+ {'key31'=>{"value31"=>{'key311'=>100, 'key312'=>"200 key3 key31"}},
115
+ 'key32'=>
116
+ {'key321'=>{"value321"=>{'key3211'=>"XXX key3 key32 key321", 'key3212'=>:XXX}}, 'key322'=>300}}}
117
117
  )
118
118
  end
119
119
 
@@ -137,15 +137,15 @@ describe Dslh do
137
137
  end
138
138
 
139
139
  expect(h).to eq(
140
- {:key1=>"value",
141
- :key2=>100,
142
- :key3=>{100=>200, "XXX"=>:XXX},
143
- :key4=>{:key41=>{"300"=>"400", :FOO=>:BAR}, :key42=>100}}
140
+ {'key1'=>"value",
141
+ 'key2'=>100,
142
+ 'key3'=>{100=>200, "XXX"=>:XXX},
143
+ 'key4'=>{'key41'=>{"300"=>"400", :FOO=>:BAR}, 'key42'=>100}}
144
144
  )
145
145
  end
146
146
 
147
147
  it 'should convert hash key/value' do
148
- h = Dslh.eval :conv => proc {|i| i.to_s } do
148
+ h = Dslh.eval :conv => proc {|i| i.to_s.to_sym } do
149
149
  key1 'value'
150
150
  key2 100
151
151
 
@@ -166,18 +166,18 @@ describe Dslh do
166
166
  end
167
167
 
168
168
  expect(h).to eq(
169
- {"key1"=>"value",
170
- "key2"=>"100",
171
- "key3"=>
172
- {"key31"=>{"value31"=>{"key311"=>"100", "key312"=>"200"}},
173
- "key32"=>
174
- {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>"XXX"}},
175
- "key322"=>"300"}}}
169
+ {:key1=>:value,
170
+ :key2=>:"100",
171
+ :key3=>
172
+ {:key31=>{:value31=>{:key311=>:"100", :key312=>:"200"}},
173
+ :key32=>
174
+ {:key321=>{:value321=>{:key3211=>:XXX, :key3212=>:XXX}},
175
+ :key322=>:"300"}}}
176
176
  )
177
177
  end
178
178
 
179
179
  it 'should convert hash key' do
180
- h = Dslh.eval :key_conv => proc {|i| i.to_s } do
180
+ h = Dslh.eval :key_conv => proc {|i| i.to_s.to_sym } do
181
181
  key1 'value'
182
182
  key2 100
183
183
 
@@ -198,13 +198,13 @@ describe Dslh do
198
198
  end
199
199
 
200
200
  expect(h).to eq(
201
- {"key1"=>"value",
202
- "key2"=>100,
203
- "key3"=>
204
- {"key31"=>{"value31"=>{"key311"=>100, "key312"=>"200"}},
205
- "key32"=>
206
- {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>:XXX}},
207
- "key322"=>300}}}
201
+ {:key1=>"value",
202
+ :key2=>100,
203
+ :key3=>
204
+ {:key31=>{"value31"=>{:key311=>100, :key312=>"200"}},
205
+ :key32=>
206
+ {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>:XXX}},
207
+ :key322=>300}}}
208
208
  )
209
209
  end
210
210
 
@@ -230,13 +230,13 @@ describe Dslh do
230
230
  end
231
231
 
232
232
  expect(h).to eq(
233
- {:key1=>"value",
234
- :key2=>"100",
235
- :key3=>
236
- {:key31=>{"value31"=>{:key311=>"100", :key312=>"200"}},
237
- :key32=>
238
- {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>"XXX"}},
239
- :key322=>"300"}}}
233
+ {"key1"=>"value",
234
+ "key2"=>"100",
235
+ "key3"=>
236
+ {"key31"=>{"value31"=>{"key311"=>"100", "key312"=>"200"}},
237
+ "key32"=>
238
+ {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>"XXX"}},
239
+ "key322"=>"300"}}}
240
240
  )
241
241
  end
242
242
 
@@ -257,10 +257,10 @@ describe Dslh do
257
257
  end
258
258
 
259
259
  expect(h).to eq(
260
- {:key1=>["value", "value2"],
261
- :key2=>[100, 200],
262
- :key3=>{:key31=>[:FOO, :BAR], :key32=>["ZOO", "BAZ"]},
263
- :key4=>{["value4", "value42"]=>{:key41=>100, :key42=>"200"}}}
260
+ {"key1"=>["value", "value2"],
261
+ "key2"=>[100, 200],
262
+ "key3"=>{"key31"=>[:FOO, :BAR], "key32"=>["ZOO", "BAZ"]},
263
+ "key4"=>{["value4", "value42"]=>{"key41"=>100, "key42"=>"200"}}}
264
264
  )
265
265
  end
266
266
 
@@ -288,12 +288,12 @@ describe Dslh do
288
288
  h = Dslh.eval(expr)
289
289
 
290
290
  expect(h).to eq(
291
- {:key1=>"value",
292
- :key2=>100,
293
- :key3=>
294
- {:key31=>{"value31"=>{:key311=>100, :key312=>"200"}},
295
- :key32=>
296
- {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>:XXX}}, :key322=>300}}}
291
+ {"key1"=>"value",
292
+ "key2"=>100,
293
+ "key3"=>
294
+ {"key31"=>{"value31"=>{"key311"=>100, "key312"=>"200"}},
295
+ "key32"=>
296
+ {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>:XXX}}, "key322"=>300}}}
297
297
  )
298
298
  end
299
299
 
@@ -321,12 +321,12 @@ describe Dslh do
321
321
  h = Dslh.eval(expr, :filename => 'my.rb', :lineno => 100)
322
322
 
323
323
  expect(h).to eq(
324
- {:key1=>"value",
325
- :key2=>100,
326
- :key3=>
327
- {:key31=>{"value31"=>{:key311=>100, :key312=>"200"}},
328
- :key32=>
329
- {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>:XXX}}, :key322=>300}}}
324
+ {"key1"=>"value",
325
+ "key2"=>100,
326
+ "key3"=>
327
+ {"key31"=>{"value31"=>{"key311"=>100, "key312"=>"200"}},
328
+ "key32"=>
329
+ {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>:XXX}}, "key322"=>300}}}
330
330
  )
331
331
  end
332
332
 
@@ -337,8 +337,8 @@ describe Dslh do
337
337
  end
338
338
 
339
339
  expect(h).to eq(
340
- {:key1 => ["value1", "value2"],
341
- :key2 => ["100", "200"]}
340
+ {"key1" => ["value1", "value2"],
341
+ "key2" => ["100", "200"]}
342
342
  )
343
343
  end
344
344
 
@@ -365,10 +365,10 @@ describe Dslh do
365
365
  end
366
366
 
367
367
  expect(h).to eq(
368
- {:key1=>"123",
369
- :key2=>
370
- {:key21=>"123", :key22=>{:key221=>"123", :key222=>"FOO"}, :key23=>"BAR"},
371
- :key3=>"ZOO"}
368
+ {"key1"=>"123",
369
+ "key2"=>
370
+ {"key21"=>"123", "key22"=>{"key221"=>"123", "key222"=>"FOO"}, "key23"=>"BAR"},
371
+ "key3"=>"ZOO"}
372
372
  )
373
373
  end
374
374
 
@@ -391,7 +391,7 @@ describe Dslh do
391
391
  end
392
392
  end
393
393
 
394
- expect(h).to eq({:key1=>123, :key2=>{:key21=>123, :key22=>{:key221=>123}}})
394
+ expect(h).to eq({"key1"=>123, "key2"=>{"key21"=>123, "key22"=>{"key221"=>123}}})
395
395
  end
396
396
 
397
397
  it 'should convert hash to dsl' do
@@ -544,7 +544,7 @@ end
544
544
  end
545
545
  end
546
546
  end
547
- }.to raise_error('duplicate key :key2')
547
+ }.to raise_error('duplicate key "key2"')
548
548
 
549
549
  expect {
550
550
  Dslh.eval do
@@ -566,7 +566,7 @@ end
566
566
  end
567
567
  end
568
568
  end
569
- }.to raise_error('duplicate key :key31')
569
+ }.to raise_error('duplicate key "key31"')
570
570
 
571
571
  expect {
572
572
  Dslh.eval do
@@ -588,7 +588,7 @@ end
588
588
  end
589
589
  end
590
590
  end
591
- }.to raise_error('duplicate key :key311')
591
+ }.to raise_error('duplicate key "key311"')
592
592
  end
593
593
 
594
594
  it 'allow duplicate key' do
@@ -706,12 +706,12 @@ end
706
706
  end
707
707
 
708
708
  expect(h).to eq(
709
- {:key1=>"value",
710
- :key2=>100,
711
- :key3=>
712
- {:key31=>{"value31"=>{:key311=>nil, :key312=>"200"}},
713
- :key32=>
714
- {:key321=>{"value321"=>{:key3211=>"XXX", :key3212=>:XXX}}, :key322=>300}}}
709
+ {"key1"=>"value",
710
+ "key2"=>100,
711
+ "key3"=>
712
+ {"key31"=>{"value31"=>{"key311"=>nil, "key312"=>"200"}},
713
+ "key32"=>
714
+ {"key321"=>{"value321"=>{"key3211"=>"XXX", "key3212"=>:XXX}}, "key322"=>300}}}
715
715
  )
716
716
  }.to_not raise_error
717
717
  end
@@ -2524,10 +2524,53 @@ end
2524
2524
 
2525
2525
  expect(h).to eq(
2526
2526
  {"system"=>
2527
- {:key1=>"value",
2528
- :key2=>100,
2529
- :key3=>{100=>200, "XXX"=>:XXX},
2530
- :key4=>{"system"=>{"300"=>"400", :FOO=>:BAR}, :key42=>100}}}
2527
+ {"key1"=>"value",
2528
+ "key2"=>100,
2529
+ "key3"=>{100=>200, "XXX"=>:XXX},
2530
+ "key4"=>{"system"=>{"300"=>"400", :FOO=>:BAR}, "key42"=>100}}}
2531
2531
  )
2532
2532
  end
2533
+
2534
+ it 'should convert hash to dsl (symbol key)' do
2535
+ h = {:glossary=>
2536
+ {:title=>"example glossary",
2537
+ :GlossDiv=>
2538
+ {:title=>"S",
2539
+ :GlossList=>
2540
+ {:GlossEntry=>
2541
+ {:ID=>"SGML",
2542
+ :SortAs=>"SGML",
2543
+ :GlossTerm=>"Standard Generalized Markup Language",
2544
+ :Acronym=>"SGML",
2545
+ :Abbrev=>"ISO 8879:1986",
2546
+ :GlossDef=>
2547
+ {:para=>
2548
+ "A meta-markup language, used to create markup languages such as DocBook.",
2549
+ :GlossSeeAlso=>["GML", "XML"]},
2550
+ :GlossSee=>"markup"}}}}}
2551
+
2552
+ dsl = Dslh.deval(h)
2553
+ expect(dsl).to eq(<<-EOS)
2554
+ glossary do
2555
+ title "example glossary"
2556
+ GlossDiv do
2557
+ title "S"
2558
+ GlossList do
2559
+ GlossEntry do
2560
+ ID "SGML"
2561
+ SortAs "SGML"
2562
+ GlossTerm "Standard Generalized Markup Language"
2563
+ Acronym "SGML"
2564
+ Abbrev "ISO 8879:1986"
2565
+ GlossDef do
2566
+ para "A meta-markup language, used to create markup languages such as DocBook."
2567
+ GlossSeeAlso "GML", "XML"
2568
+ end
2569
+ GlossSee "markup"
2570
+ end
2571
+ end
2572
+ end
2573
+ end
2574
+ EOS
2575
+ end
2533
2576
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-14 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler