slaw 0.6.9 → 0.6.10

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: c547c592602183d308cb921d933342705d3abfc5
4
- data.tar.gz: 6c51e8eb899baa73562df3e6ce80f6d29ad7e048
3
+ metadata.gz: 509885e0ab8866ac5793804d77249885c141b2dc
4
+ data.tar.gz: 20f4d702127bbe215f4710e25587c10f2e07b73e
5
5
  SHA512:
6
- metadata.gz: b529abf4b1c3040c3217a02ea2abf5ac534f76cca5863b0c5d84049a835d5a835247d0b0768c75bf80aae9cefdca57409573f162cad4e78324a28c6f84646f01
7
- data.tar.gz: 5405a71b050b492e998e01a6e29d8c7cf02d498912759207902b81114bbc76e3aae487d0de1112a23114e7c4aabf8f04d9c634be2ee326168e49237f75d72997
6
+ metadata.gz: cca31525dc5bed1c19ff6be61b5a167b6debfe42b59f196c55624d9b4e333f86480b6a8ff0100a43e7ac8086489d4352a7d27ef0bc1745cdc9b9c18b17343216
7
+ data.tar.gz: 4a8af41380e9a45d3785844347e17fae18de1669ce41ada5989dff2d807dcaefbaeda7f89a0d1b15b8d6aeaf9d98ff2cea2e61799dd45867094a5ed3fceeb31b
data/lib/slaw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "0.6.9"
2
+ VERSION = "0.6.10"
3
3
  end
@@ -12,13 +12,21 @@ module Slaw
12
12
  # major containers
13
13
 
14
14
  rule act
15
- preamble
15
+ empty_line*
16
+ preface:preface?
17
+ preamble:preamble?
16
18
  chapters:chapter*
17
19
  schedules:schedules <Act>
18
20
  end
19
21
 
22
+ rule preface
23
+ !'PREAMBLE'
24
+ ('PREFACE'i space? eol)?
25
+ statements:(!'PREAMBLE' naked_statement)* <Preface>
26
+ end
27
+
20
28
  rule preamble
21
- empty_line*
29
+ 'PREAMBLE'i space? eol
22
30
  statements:naked_statement* <Preamble>
23
31
  end
24
32
 
@@ -12,6 +12,7 @@ module Slaw
12
12
  def to_xml(b, idprefix)
13
13
  b.act(contains: "originalVersion") { |b|
14
14
  write_meta(b)
15
+ write_preface(b)
15
16
  write_preamble(b)
16
17
  write_body(b)
17
18
  }
@@ -57,6 +58,10 @@ module Slaw
57
58
  }
58
59
  end
59
60
 
61
+ def write_preface(b)
62
+ preface.to_xml(b)
63
+ end
64
+
60
65
  def write_preamble(b)
61
66
  preamble.to_xml(b)
62
67
  end
@@ -72,14 +77,26 @@ module Slaw
72
77
  end
73
78
  end
74
79
 
80
+ class Preface < Treetop::Runtime::SyntaxNode
81
+ def to_xml(b)
82
+ if text_value != ""
83
+ b.preface { |b|
84
+ statements.elements.each { |element|
85
+ for e in element.elements
86
+ e.to_xml(b, "") if e.is_a? NakedStatement
87
+ end
88
+ }
89
+ }
90
+ end
91
+ end
92
+ end
93
+
75
94
  class Preamble < Treetop::Runtime::SyntaxNode
76
95
  def to_xml(b)
77
96
  if text_value != ""
78
97
  b.preamble { |b|
79
98
  statements.elements.each { |e|
80
- if not (e.clauses.text_value =~ /^preamble/i)
81
- b.p(e.clauses.text_value)
82
- end
99
+ e.to_xml(b, "")
83
100
  }
84
101
  }
85
102
  end
data/spec/za/act_spec.rb CHANGED
@@ -139,7 +139,7 @@ PREVENTION AND SUPPRESSION OF HEALTH NUISANCES
139
139
  No owner or occupier of any shop or business premises or vacant land adjoining a shop or business premises shall cause a health nuisance.
140
140
  EOS
141
141
 
142
- part = node.elements[1].elements[0].elements[1].elements[0]
142
+ part = node.chapters.elements[0].parts.elements[0]
143
143
  part.heading.num.should == "1"
144
144
  part.heading.title.should == "PREVENTION AND SUPPRESSION OF HEALTH NUISANCES"
145
145
 
@@ -412,6 +412,8 @@ EOS
412
412
 
413
413
  Some content
414
414
  EOS
415
+
416
+ today = Time.now.strftime('%Y-%m-%d')
415
417
  to_xml(node, "").should == '<doc name="schedule1">
416
418
  <meta>
417
419
  <identification source="#slaw">
@@ -433,7 +435,7 @@ EOS
433
435
  <FRBRManifestation>
434
436
  <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
435
437
  <FRBRuri value="/za/act/1980/01/eng@"/>
436
- <FRBRdate date="2015-05-20" name="Generation"/>
438
+ <FRBRdate date="' + today + '" name="Generation"/>
437
439
  <FRBRauthor href="#slaw" as="#author"/>
438
440
  </FRBRManifestation>
439
441
  </identification>
@@ -464,10 +466,10 @@ EOS
464
466
  end
465
467
 
466
468
  #-------------------------------------------------------------------------------
467
- # Preamble
469
+ # Preface
468
470
 
469
- context 'preamble' do
470
- it 'should consider any text at the start to be preamble' do
471
+ context 'preface' do
472
+ it 'should consider any text at the start to be preface' do
471
473
  node = parse :act, <<EOS
472
474
  foo
473
475
  bar
@@ -478,7 +480,7 @@ baz
478
480
  (1) hello
479
481
  EOS
480
482
 
481
- node.elements.first.text_value.should == "foo
483
+ node.preface.text_value.should == "foo
482
484
  bar
483
485
  (1) stuff
484
486
  (2) more stuff
@@ -486,6 +488,99 @@ baz
486
488
  "
487
489
  end
488
490
 
491
+ it 'should support an optional preface' do
492
+ node = parse :act, <<EOS
493
+ PREFACE
494
+ foo
495
+ 1. Section
496
+ (1) hello
497
+ EOS
498
+
499
+ node.preface.text_value.should == "PREFACE\nfoo\n"
500
+ to_xml(node.preface).should == '<preface>
501
+ <p>foo</p>
502
+ </preface>'
503
+ end
504
+
505
+ it 'should support remarks in the preface' do
506
+ node = parse :act, <<EOS
507
+ PREFACE
508
+
509
+ [[remark]]
510
+
511
+ foo
512
+
513
+ [[ another remark]]
514
+
515
+ 1. Section
516
+ (1) hello
517
+ EOS
518
+
519
+ to_xml(node.preface).should == '<preface>
520
+ <p>
521
+ <remark status="editorial">[remark]</remark>
522
+ </p>
523
+ <p>foo</p>
524
+ <p>
525
+ <remark status="editorial">[ another remark]</remark>
526
+ </p>
527
+ </preface>'
528
+ end
529
+
530
+ it 'should support no preface' do
531
+ node = parse :act, <<EOS
532
+ 1. Section
533
+ bar
534
+ EOS
535
+
536
+ node.preface.text_value.should == ""
537
+ end
538
+
539
+ it 'should support prefaces and preambles' do
540
+ node = parse :act, <<EOS
541
+ this is in the preface
542
+
543
+ PREAMBLE
544
+
545
+ this is in the preamble
546
+
547
+ 1. Section
548
+ (1) hello
549
+ EOS
550
+
551
+ to_xml(node.preface).should == '<preface>
552
+ <p>this is in the preface</p>
553
+ </preface>'
554
+ to_xml(node.preamble).should == '<preamble>
555
+ <p>this is in the preamble</p>
556
+ </preamble>'
557
+ end
558
+
559
+ it 'should support prefaces and preambles' do
560
+ node = parse :act, <<EOS
561
+ PREFACE
562
+ this is in the preface
563
+
564
+ PREAMBLE
565
+ this is in the preamble
566
+
567
+ 1. Section
568
+ (1) hello
569
+ EOS
570
+
571
+ to_xml(node.preface).should == '<preface>
572
+ <p>this is in the preface</p>
573
+ </preface>'
574
+ to_xml(node.preamble).should == '<preamble>
575
+ <p>this is in the preamble</p>
576
+ </preamble>'
577
+ end
578
+ end
579
+
580
+ #-------------------------------------------------------------------------------
581
+ # Preamble
582
+
583
+ context 'preamble' do
489
584
  it 'should support an optional preamble' do
490
585
  node = parse :act, <<EOS
491
586
  PREAMBLE
@@ -494,7 +589,35 @@ foo
494
589
  (1) hello
495
590
  EOS
496
591
 
497
- node.elements.first.text_value.should == "PREAMBLE\nfoo\n"
592
+ node.preamble.text_value.should == "PREAMBLE\nfoo\n"
593
+ to_xml(node.preamble).should == '<preamble>
594
+ <p>foo</p>
595
+ </preamble>'
596
+ end
597
+
598
+ it 'should support remarks in the preamble' do
599
+ node = parse :act, <<EOS
600
+ PREAMBLE
601
+
602
+ [[remark]]
603
+
604
+ foo
605
+
606
+ [[ another remark]]
607
+
608
+ 1. Section
609
+ (1) hello
610
+ EOS
611
+
612
+ to_xml(node.preamble).should == '<preamble>
613
+ <p>
614
+ <remark status="editorial">[remark]</remark>
615
+ </p>
616
+ <p>foo</p>
617
+ <p>
618
+ <remark status="editorial">[ another remark]</remark>
619
+ </p>
620
+ </preamble>'
498
621
  end
499
622
 
500
623
  it 'should support no preamble' do
@@ -507,7 +630,6 @@ EOS
507
630
  end
508
631
  end
509
632
 
510
-
511
633
  #-------------------------------------------------------------------------------
512
634
  # Sections
513
635
 
@@ -519,7 +641,7 @@ Section
519
641
  1. (1) hello
520
642
  EOS
521
643
 
522
- section = node.elements[1].elements[0].elements[1].elements[0].elements[1].elements[0]
644
+ section = node.chapters.elements.first.parts.elements.first.sections.elements.first
523
645
  section.section_title.content.text_value.should == "Section"
524
646
  section.section_title.section_title_prefix.number_letter.text_value.should == "1"
525
647
  end
@@ -531,7 +653,7 @@ EOS
531
653
  (1) hello
532
654
  EOS
533
655
 
534
- section = node.elements[1].elements[0].elements[1].elements[0].elements[1].elements[0]
656
+ section = node.chapters.elements.first.parts.elements.first.sections.elements.first
535
657
  section.section_title.title.should == "Section"
536
658
  section.section_title.num.should == "1"
537
659
  end
@@ -545,11 +667,11 @@ EOS
545
667
  (2) Another line
546
668
  EOS
547
669
 
548
- section = node.elements[1].elements[0].elements[1].elements[0].elements[1].elements[0]
670
+ section = node.chapters.elements.first.parts.elements.first.sections.elements.first
549
671
  section.section_title.title.should == "A section"
550
672
  section.section_title.num.should == "1"
551
673
 
552
- section = node.elements[1].elements[0].elements[1].elements[0].elements[1].elements[1]
674
+ section = node.chapters.elements[0].parts.elements.first.sections.elements[1]
553
675
  section.section_title.title.should == "Another section"
554
676
  section.section_title.num.should == "2"
555
677
  end
@@ -561,7 +683,7 @@ EOS
561
683
  (2) Without limiting generality, stuff.
562
684
  EOS
563
685
 
564
- section = node.elements[1].elements[0].elements[1].elements[0].elements[1].elements[0]
686
+ section = node.chapters.elements.first.parts.elements.first.sections.elements.first
565
687
  section.section_title.title.should == ""
566
688
  section.section_title.num.should == "10"
567
689
  section.subsections.elements[0].statement.num.should == "(1)"
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: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Kempe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler