slaw 0.7.1 → 0.7.2

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: ab0729eacd76a7bf7f4cd639986b5a892a635125
4
- data.tar.gz: c9994dc951d991553f55709a22cd8d21e6bb9aa7
3
+ metadata.gz: 9da16bde12dc6832dbf6772de7205268e7ebe3d2
4
+ data.tar.gz: 74eb889730d1be5cf02a656f410cf66f7878fa50
5
5
  SHA512:
6
- metadata.gz: 4d40d3cba28815aed221a31216dc6d337300f0cc74925e816f974c5a42e3e427a88b2a18010aafb554bc9b9ffc4fe691b7d4bcadeadfee6022bb198e2425c469
7
- data.tar.gz: 42653d4f00bf24f9d7345938255ab49d725ef197adda131410d7317dd8d30dcec34f61cf66c6da48dcffbaf57fd63a61398973c332cd98a9d763c3a3d80cf734
6
+ metadata.gz: c5b5d462affc8dc8e2a39fffee9c6612f1755746a9c5c3c31b654515f9062dd060ef0f9aebc383dd92e1799db583bac41ccb72abc0bdeaec3e44051f54fd9932
7
+ data.tar.gz: d06d15f2768bd2abb2aae5ca2919975d55e75acde2e4c256099c96e75aac84b01cb43832db2146836be9c864a945045100778c8897f901c0eb54a434d8626c37
data/README.md CHANGED
@@ -213,3 +213,14 @@ Akoma Ntoso `component` elements at the end of the XML document, with a name of
213
213
  3. Commit your changes (`git commit -am 'Add some feature'`)
214
214
  4. Push to the branch (`git push origin my-new-feature`)
215
215
  5. Create new Pull Request
216
+
217
+ ## Changelog
218
+
219
+ ### 0.7.2
220
+
221
+ * add --section-number-position argument to slaw command
222
+ * grammar supports empty chapters and parts
223
+
224
+ ### 0.7.1
225
+
226
+ * major changes to grammar to permit chapters, parts, sections etc. in schedules
data/bin/slaw CHANGED
@@ -14,6 +14,7 @@ class SlawCLI < Thor
14
14
  option :definitions, type: :boolean, desc: "Find and link definitions (this can be slow). Default: false"
15
15
  option :fragment, type: :string, desc: "Akoma Ntoso element name that the imported text represents. Support depends on the grammar."
16
16
  option :id_prefix, type: :string, desc: "Prefix to be used when generating ID elements when parsing a fragment."
17
+ option :section_number_position, enum: ['before-title', 'after-title', 'guess'], desc: "Where do section titles come in relation to the section number? Default: before-title"
17
18
  def parse(name)
18
19
  logging
19
20
 
@@ -56,6 +57,18 @@ class SlawCLI < Thor
56
57
  end
57
58
  end
58
59
 
60
+ case (options[:section_number_position] || "before-title")
61
+ when "before-title"
62
+ generator.parser.options[:section_number_after_title] = false
63
+ when "after-title"
64
+ generator.parser.options[:section_number_after_title] = true
65
+ when "guess"
66
+ after = generator.guess_section_number_after_title(text)
67
+ error "guessed section number position is #{after ? "after-title" : "before-title"}"
68
+
69
+ generator.parser.options[:section_number_after_title] = after
70
+ end
71
+
59
72
  begin
60
73
  act = generator.generate_from_text(text)
61
74
  rescue Slaw::Parse::ParseError => e
@@ -35,5 +35,24 @@ module Slaw
35
35
  text = @cleanser.reformat(text)
36
36
  text
37
37
  end
38
+
39
+ # Try to determine if section numbers come after titles,
40
+ # rather than before.
41
+ #
42
+ # eg:
43
+ #
44
+ # Section title
45
+ # 1. Section content
46
+ #
47
+ # versus
48
+ #
49
+ # 1. Section title
50
+ # Section content
51
+ def guess_section_number_after_title(text)
52
+ before = text.scan(/^\w{4,}[^\n]+\n\d+\. /).length
53
+ after = text.scan(/^\s*\n\d+\. \w{4,}/).length
54
+
55
+ before > after * 1.25
56
+ end
38
57
  end
39
58
  end
data/lib/slaw/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slaw
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -36,13 +36,13 @@ module Slaw
36
36
 
37
37
  rule chapter
38
38
  heading:chapter_heading
39
- children:(part / section / block_paragraphs / subsection)+
39
+ children:(part / section / block_paragraphs / subsection)*
40
40
  <Chapter>
41
41
  end
42
42
 
43
43
  rule part
44
44
  heading:part_heading
45
- children:(section / block_paragraphs / subsection)+
45
+ children:(section / block_paragraphs / subsection)*
46
46
  <Part>
47
47
  end
48
48
 
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'slaw'
5
+
6
+ describe Slaw::ActGenerator do
7
+ describe 'guess_section_number_after_title' do
8
+ context 'section number after title' do
9
+ it 'should work' do
10
+ text = "
11
+ Section title
12
+ 1. Section content
13
+
14
+ Another section title
15
+ 2. Section content that is long.
16
+ "
17
+ subject.guess_section_number_after_title(text).should be_true
18
+ end
19
+ end
20
+
21
+ context 'section number before title' do
22
+ it 'should default to false' do
23
+ subject.guess_section_number_after_title("").should be_false
24
+ end
25
+
26
+ it 'should be false' do
27
+ text = "
28
+ Mistaken title
29
+ 1. Section title
30
+
31
+ Some content.
32
+
33
+ 2. Second title
34
+
35
+ Some content.
36
+ "
37
+ subject.guess_section_number_after_title(text).should be_false
38
+ end
39
+ end
40
+ end
41
+ end
data/spec/za/act_spec.rb CHANGED
@@ -215,6 +215,23 @@ EOS
215
215
  </section>
216
216
  </chapter>'
217
217
  end
218
+
219
+ it 'should handle empty chapters' do
220
+ node = parse :body, <<EOS
221
+ Chapter 2 The Chapter Heading
222
+ Chapter 3 The Other Heading
223
+ EOS
224
+ to_xml(node).should == '<body>
225
+ <chapter id="chapter-2">
226
+ <num>2</num>
227
+ <heading>The Chapter Heading</heading>
228
+ </chapter>
229
+ <chapter id="chapter-3">
230
+ <num>3</num>
231
+ <heading>The Other Heading</heading>
232
+ </chapter>
233
+ </body>'
234
+ end
218
235
  end
219
236
 
220
237
  #-------------------------------------------------------------------------------
@@ -382,6 +399,23 @@ EOS
382
399
  </section>
383
400
  </part>'
384
401
  end
402
+
403
+ it 'should handle empty parts' do
404
+ node = parse :body, <<EOS
405
+ Part 2 The Part Heading
406
+ Part 3 The Other Heading
407
+ EOS
408
+ to_xml(node).should == '<body>
409
+ <part id="part-2">
410
+ <num>2</num>
411
+ <heading>The Part Heading</heading>
412
+ </part>
413
+ <part id="part-3">
414
+ <num>3</num>
415
+ <heading>The Other Heading</heading>
416
+ </part>
417
+ </body>'
418
+ end
385
419
  end
386
420
 
387
421
  #-------------------------------------------------------------------------------
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.7.1
4
+ version: 0.7.2
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-07-23 00:00:00.000000000 Z
11
+ date: 2015-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -196,6 +196,7 @@ files:
196
196
  - spec/bylaw_spec.rb
197
197
  - spec/extract/extractor_spec.rb
198
198
  - spec/fixtures/community-fire-safety.xml
199
+ - spec/generator_spec.rb
199
200
  - spec/parse/builder_spec.rb
200
201
  - spec/parse/cleanser_spec.rb
201
202
  - spec/spec_helper.rb
@@ -230,6 +231,7 @@ test_files:
230
231
  - spec/bylaw_spec.rb
231
232
  - spec/extract/extractor_spec.rb
232
233
  - spec/fixtures/community-fire-safety.xml
234
+ - spec/generator_spec.rb
233
235
  - spec/parse/builder_spec.rb
234
236
  - spec/parse/cleanser_spec.rb
235
237
  - spec/spec_helper.rb