slaw 1.0.0.alpha.4 → 1.0.0.alpha.5

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: a2fbb349a6f18f3b78feda6a8242e3688db6f65b
4
- data.tar.gz: 6dc113e8c0194a813b5a0837fc6bb5dabdfe7570
3
+ metadata.gz: 8377cd0de850d01757d9521eb73e57840e5ae857
4
+ data.tar.gz: df62a774c045f204e90f2ddf9b3278b00310ee0b
5
5
  SHA512:
6
- metadata.gz: a3941935634b014c79358c16784acfb32ac16f6fd083b4a9f31a029fb90d0f19eff4ca4eca29e71e54348a9458617c53a661b0537d2b4922157dba6fdd64f7ff
7
- data.tar.gz: f76579ebb6a935e1c46a3ef4ba5eaafe3761673408fc35006c5036d677650aeaa534335095bff3ca139bb8e09a5df8bf384dc4071f432d5c5053a933391e76bf
6
+ metadata.gz: 9ec34a0c15fd5c9017774e60eba1020c87e584c75b928998682c92399fc95c7403dffcfd294937178605f126d8180df7405be614960e74e72b22c2125e475b5b
7
+ data.tar.gz: 1f095a2dea3d24e88aedd838e678a7c916602075dad24d2f8ed6475aeec6988332c1916a0c284173616021cac0dbdce96ce0b5f67d484abb3ed14e4751135da6
@@ -59,39 +59,35 @@ module Slaw
59
59
  end
60
60
 
61
61
  rule article
62
- # Art. 55. 1. something
63
- article_prefix whitespace
64
- intro:block_element?
62
+ # Art. 55. some optional text
63
+ # 1. first paragraph etc.
64
+ article_prefix intro
65
65
  children:(section / paragraph / point / litera / indents / block_paragraphs)* <Article>
66
66
  end
67
67
 
68
68
  rule section
69
69
  # § 55. foo
70
- section_prefix whitespace
71
- intro:block_element?
70
+ section_prefix intro
72
71
  children:(paragraph / point / litera / indents / block_paragraphs)* <Section>
73
72
  end
74
73
 
75
74
  rule paragraph
76
75
  # ustęp:
77
76
  # 34. ...
78
- paragraph_prefix whitespace
79
- intro:block_element?
77
+ paragraph_prefix intro
80
78
  children:(point / litera / indents / block_paragraphs)* <Paragraph>
81
79
  end
82
80
 
83
81
  rule point
84
82
  # 12) aoeuaoeu
85
83
  # 12a) aoeuaoeu
86
- point_prefix whitespace
87
- intro:block_element?
84
+ point_prefix intro
88
85
  children:(litera / indents / block_paragraphs)* <Point>
89
86
  end
90
87
 
91
88
  rule litera
92
89
  # a) aoeuaoeu
93
- litera_prefix whitespace
94
- intro:block_element?
90
+ litera_prefix intro
95
91
  children:(indents / block_paragraphs)* <Litera>
96
92
  end
97
93
 
@@ -105,6 +101,10 @@ module Slaw
105
101
  indent_prefix item_content:inline_block_element? eol? <IndentItem>
106
102
  end
107
103
 
104
+ rule intro
105
+ (intro_inline:inline_block_element / (eol intro_block:block_element))? eol?
106
+ end
107
+
108
108
  ##########
109
109
  # group elements
110
110
  #
@@ -241,4 +241,3 @@ module Slaw
241
241
  end
242
242
  end
243
243
  end
244
-
@@ -191,7 +191,35 @@ module Slaw
191
191
  end
192
192
  end
193
193
 
194
- class Article < Treetop::Runtime::SyntaxNode
194
+ class BlockWithIntroAndChildren < Treetop::Runtime::SyntaxNode
195
+ def intro_node
196
+ if intro.elements.length >= 1
197
+ el = intro.elements[0]
198
+
199
+ if el.respond_to? :intro_inline
200
+ el.intro_inline
201
+ elsif el.respond_to? :intro_block
202
+ el.intro_block
203
+ end
204
+ end
205
+ end
206
+
207
+ def intro_and_children_xml(b, idprefix)
208
+ if intro_node and !intro_node.empty?
209
+ if not children.empty?
210
+ b.intro { |b| intro_node.to_xml(b, idprefix) }
211
+ else
212
+ b.content { |b| intro_node.to_xml(b, idprefix) }
213
+ end
214
+ elsif children.empty?
215
+ b.content { |b| b.p }
216
+ end
217
+
218
+ children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
219
+ end
220
+ end
221
+
222
+ class Article < BlockWithIntroAndChildren
195
223
  def num
196
224
  article_prefix.number_letter.text_value
197
225
  end
@@ -202,23 +230,12 @@ module Slaw
202
230
 
203
231
  b.article(id: id) { |b|
204
232
  b.num("#{num}.")
205
-
206
- if !intro.empty?
207
- if not children.empty?
208
- b.intro { |b| intro.to_xml(b, idprefix) }
209
- else
210
- b.content { |b| intro.to_xml(b, idprefix) }
211
- end
212
- elsif children.empty?
213
- b.content { |b| b.p }
214
- end
215
-
216
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
233
+ intro_and_children_xml(b, idprefix)
217
234
  }
218
235
  end
219
236
  end
220
237
 
221
- class Section < Treetop::Runtime::SyntaxNode
238
+ class Section < BlockWithIntroAndChildren
222
239
  def num
223
240
  section_prefix.alphanums.text_value
224
241
  end
@@ -229,23 +246,12 @@ module Slaw
229
246
 
230
247
  b.section(id: id) { |b|
231
248
  b.num("#{num}.")
232
-
233
- if !intro.empty?
234
- if not children.empty?
235
- b.intro { |b| intro.to_xml(b, idprefix) }
236
- else
237
- b.content { |b| intro.to_xml(b, idprefix) }
238
- end
239
- elsif children.empty?
240
- b.content { |b| b.p }
241
- end
242
-
243
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
249
+ intro_and_children_xml(b, idprefix)
244
250
  }
245
251
  end
246
252
  end
247
253
 
248
- class Paragraph < Treetop::Runtime::SyntaxNode
254
+ class Paragraph < BlockWithIntroAndChildren
249
255
  def num
250
256
  paragraph_prefix.number_letter.text_value
251
257
  end
@@ -256,23 +262,12 @@ module Slaw
256
262
 
257
263
  b.paragraph(id: id) { |b|
258
264
  b.num(paragraph_prefix.text_value)
259
-
260
- if !intro.empty?
261
- if not children.empty?
262
- b.intro { |b| intro.to_xml(b, idprefix) }
263
- else
264
- b.content { |b| intro.to_xml(b, idprefix) }
265
- end
266
- elsif children.empty?
267
- b.content { |b| b.p }
268
- end
269
-
270
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
265
+ intro_and_children_xml(b, idprefix)
271
266
  }
272
267
  end
273
268
  end
274
269
 
275
- class Point < Treetop::Runtime::SyntaxNode
270
+ class Point < BlockWithIntroAndChildren
276
271
  def num
277
272
  point_prefix.number_letter.text_value
278
273
  end
@@ -283,23 +278,12 @@ module Slaw
283
278
 
284
279
  b.point(id: id) { |b|
285
280
  b.num(point_prefix.text_value)
286
-
287
- if !intro.empty?
288
- if not children.empty?
289
- b.intro { |b| intro.to_xml(b, idprefix) }
290
- else
291
- b.content { |b| intro.to_xml(b, idprefix) }
292
- end
293
- elsif children.empty?
294
- b.content { |b| b.p }
295
- end
296
-
297
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
281
+ intro_and_children_xml(b, idprefix)
298
282
  }
299
283
  end
300
284
  end
301
285
 
302
- class Litera < Treetop::Runtime::SyntaxNode
286
+ class Litera < BlockWithIntroAndChildren
303
287
  def num
304
288
  litera_prefix.letters.text_value
305
289
  end
@@ -310,18 +294,7 @@ module Slaw
310
294
 
311
295
  b.list(id: id) { |b|
312
296
  b.num(litera_prefix.text_value)
313
-
314
- if !intro.empty?
315
- if not children.empty?
316
- b.intro { |b| intro.to_xml(b, idprefix) }
317
- else
318
- b.content { |b| intro.to_xml(b, idprefix) }
319
- end
320
- elsif children.empty?
321
- b.content { |b| b.p }
322
- end
323
-
324
- children.elements.each_with_index { |e, i| e.to_xml(b, idprefix, i) }
297
+ intro_and_children_xml(b, idprefix)
325
298
  }
326
299
  end
327
300
  end
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "1.0.0.alpha.4"
2
+ VERSION = "1.0.0.alpha.5"
3
3
  end
@@ -41,12 +41,14 @@ Rozdział 7. Oznaczanie przepisów ustawy i ich systematyzacja
41
41
 
42
42
  § 54. Podstawową jednostką redakcyjną ustawy jest artykuł.
43
43
 
44
- § 55. 1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.
44
+ § 55.
45
+ 1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.
45
46
  2. Artykuł powinien być w miarę możliwości jednozdaniowy.
46
47
  3. Jeżeli samodzielną myśl wyraża zespół zdań, dokonuje się podziału artykułu na ustępy. W ustawie określanej jako "kodeks" ustępy oznacza się paragrafami (§).
47
48
  4. Podział artykułu na ustępy wprowadza się także w przypadku, gdy między zdaniami wyrażającymi samodzielne myśli występują powiązania treściowe, ale treść żadnego z nich nie jest na tyle istotna, aby wydzielić ją w odrębny artykuł.
48
49
 
49
- § 56. 1. W obrębie artykułu (ustępu) zawierającego wyliczenie wyróżnia się dwie części: wprowadzenie do wyliczenia oraz punkty. Wyliczenie może kończyć się częścią wspólną, odnoszącą się do wszystkich punktów. Po części wspólnej nie dodaje się kolejnej samodzielnej myśli; w razie potrzeby formułuje się ją w kolejnym ustępie.
50
+ § 56.
51
+ 1. W obrębie artykułu (ustępu) zawierającego wyliczenie wyróżnia się dwie części: wprowadzenie do wyliczenia oraz punkty. Wyliczenie może kończyć się częścią wspólną, odnoszącą się do wszystkich punktów. Po części wspólnej nie dodaje się kolejnej samodzielnej myśli; w razie potrzeby formułuje się ją w kolejnym ustępie.
50
52
  2. W obrębie punktów można dokonać dalszego wyliczenia, wprowadzając litery.
51
53
  EOS
52
54
 
@@ -131,6 +133,20 @@ EOS
131
133
  </article>'
132
134
  end
133
135
 
136
+ it 'should handle articles with blank lines' do
137
+ node = parse :article, <<EOS
138
+ Art. 1.
139
+
140
+ Ustawa reguluje opodatkowanie podatkiem dochodowym dochodów osób fizycznych
141
+ EOS
142
+ to_xml(node).should == '<article id="article-1">
143
+ <num>1.</num>
144
+ <content>
145
+ <p>Ustawa reguluje opodatkowanie podatkiem dochodowym dochodów osób fizycznych</p>
146
+ </content>
147
+ </article>'
148
+ end
149
+
134
150
  it 'should handle consecutive articles' do
135
151
  node = parse :body, <<EOS
136
152
  Art. 1. Ustawa reguluje opodatkowanie podatkiem dochodowym dochodów osób fizycznych
@@ -154,7 +170,8 @@ EOS
154
170
 
155
171
  it 'should handle nested content' do
156
172
  node = parse :article, <<EOS
157
- Art. 2. 1. Przepisów ustawy nie stosuje się do:
173
+ Art. 2.
174
+ 1. Przepisów ustawy nie stosuje się do:
158
175
  1) przychodów z działalności rolniczej, z wyjątkiem przychodów z działów specjalnych produkcji rolnej;
159
176
  2) przychodów z gospodarki leśnej w rozumieniu ustawy o lasach;
160
177
  EOS
@@ -266,6 +283,21 @@ EOS
266
283
  </paragraph>'
267
284
  end
268
285
 
286
+ it 'should handle a para with whitespace' do
287
+ node = parse :paragraph, <<EOS
288
+ 1.
289
+
290
+ foo bar
291
+ EOS
292
+
293
+ to_xml(node).should == '<paragraph id="paragraph-1">
294
+ <num>1.</num>
295
+ <content>
296
+ <p>foo bar</p>
297
+ </content>
298
+ </paragraph>'
299
+ end
300
+
269
301
  it 'should handle paragraphs with points' do
270
302
  node = parse :paragraph, <<EOS
271
303
  2. W ustawie należy unikać posługiwania się:
@@ -297,6 +329,33 @@ EOS
297
329
  <p>nowo tworzonymi pojęciami lub strukturami językowymi, chyba że w dotychczasowym słownictwie polskim brak jest odpowiedniego określenia.</p>
298
330
  </content>
299
331
  </point>
332
+ </paragraph>'
333
+ end
334
+
335
+ it 'should not get confused by points with articles' do
336
+ node = parse :paragraph, <<EOS
337
+ 2. W ustawie należy unikać posługiwania się:
338
+ 1) art. 1
339
+ 2) art. 2
340
+ EOS
341
+
342
+ to_xml(node).should == '<paragraph id="paragraph-2">
343
+ <num>2.</num>
344
+ <intro>
345
+ <p>W ustawie należy unikać posługiwania się:</p>
346
+ </intro>
347
+ <point id="paragraph-2.point-1">
348
+ <num>1)</num>
349
+ <content>
350
+ <p>art. 1</p>
351
+ </content>
352
+ </point>
353
+ <point id="paragraph-2.point-2">
354
+ <num>2)</num>
355
+ <content>
356
+ <p>art. 2</p>
357
+ </content>
358
+ </point>
300
359
  </paragraph>'
301
360
  end
302
361
  end
@@ -335,7 +394,8 @@ EOS
335
394
 
336
395
  it 'should handle section with numbered paras' do
337
396
  node = parse :section, <<EOS
338
- § 55. 1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.
397
+ § 55.
398
+ 1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.
339
399
  2. Artykuł powinien być w miarę możliwości jednozdaniowy.
340
400
  3. Jeżeli samodzielną myśl wyraża zespół zdań, dokonuje się podziału artykułu na ustępy. W ustawie określanej jako "kodeks" ustępy oznacza się paragrafami (§).
341
401
  EOS
@@ -363,6 +423,26 @@ EOS
363
423
  </section>'
364
424
  end
365
425
 
426
+ it 'should not confuse section content with block elements' do
427
+ node = parse :section, <<EOS
428
+ § 55. 1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.
429
+ 3. Jeżeli samodzielną myśl wyraża zespół zdań, dokonuje się podziału artykułu na ustępy. W ustawie określanej jako "kodeks" ustępy oznacza się paragrafami (§).
430
+ EOS
431
+
432
+ to_xml(node).should == '<section id="section-55">
433
+ <num>55.</num>
434
+ <intro>
435
+ <p>1. Każdą samodzielną myśl ujmuje się w odrębny artykuł.</p>
436
+ </intro>
437
+ <paragraph id="section-55.paragraph-3">
438
+ <num>3.</num>
439
+ <content>
440
+ <p>Jeżeli samodzielną myśl wyraża zespół zdań, dokonuje się podziału artykułu na ustępy. W ustawie określanej jako "kodeks" ustępy oznacza się paragrafami (§).</p>
441
+ </content>
442
+ </paragraph>
443
+ </section>'
444
+ end
445
+
366
446
  it 'should handle section with intro, para and points' do
367
447
  node = parse :section, <<EOS
368
448
  § 54. Podstawową jednostką redakcyjną ustawy jest artykuł.
@@ -395,6 +475,19 @@ EOS
395
475
  <p>second point</p>
396
476
  </content>
397
477
  </point>
478
+ </section>'
479
+ end
480
+
481
+ it 'should not get confused by sections with articles' do
482
+ node = parse :section, <<EOS
483
+ § 54. Art 1. is changed...
484
+ EOS
485
+
486
+ to_xml(node).should == '<section id="section-54">
487
+ <num>54.</num>
488
+ <content>
489
+ <p>Art 1. is changed...</p>
490
+ </content>
398
491
  </section>'
399
492
  end
400
493
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.4
4
+ version: 1.0.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Kempe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-15 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler