bible_reference_parser 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ # Shared examples for classes including the TracksErrors module
2
+
3
+ module ItTracksErrors
4
+ shared_examples_for "it tracks errors" do |new_instance|
5
+ before :each do
6
+ new_instance.clear_errors
7
+ end
8
+
9
+ describe "initialization" do
10
+ it "should set the errors attribute to a kind of array" do
11
+ new_instance.errors.should be_kind_of Array
12
+ end
13
+
14
+ it "should set the errors attribute to empty" do
15
+ new_instance.errors.should be_empty
16
+ end
17
+ end
18
+
19
+ describe "The 'add_error' method" do
20
+ it "should add an error message to the errors collection" do
21
+ new_instance.add_error "invalid"
22
+ new_instance.errors.length.should eql 1
23
+ new_instance.errors.first.should eql "invalid"
24
+ end
25
+ end
26
+
27
+ describe "the 'clear_errors?' method" do
28
+ it "should erase all errors" do
29
+ new_instance.add_error "invalid"
30
+ new_instance.clear_errors
31
+ new_instance.errors.should be_empty
32
+ end
33
+ end
34
+
35
+ describe "the 'has_errors?' method" do
36
+ it "should return whether there are any error messages" do
37
+ new_instance.has_errors?.should be_false
38
+ new_instance.add_error "invalid"
39
+ new_instance.has_errors?.should be_true
40
+ end
41
+ end
42
+
43
+ describe "the 'no_errors?' method" do
44
+ it "should return whether there are any error messages" do
45
+ new_instance.no_errors?.should be_true
46
+ new_instance.add_error "invalid"
47
+ new_instance.no_errors?.should be_false
48
+ end
49
+ end
50
+
51
+ describe "the 'errors' method" do
52
+ before :each do
53
+ @allows_children = new_instance.respond_to?("children") && new_instance.children
54
+ new_instance.children.clear_errors if @allows_children
55
+ end
56
+
57
+ it "should not include child errors if include_child_errors is false" do
58
+ new_instance.add_error "invalid"
59
+ new_instance.children.add_error "invalid_child" if @allows_children
60
+
61
+ errors = new_instance.errors(false)
62
+ errors.count.should eql 1
63
+ errors.first.should eql "invalid"
64
+ end
65
+
66
+ it "should include child errors if include_child_errors is true" do
67
+ new_instance.add_error "invalid"
68
+ new_instance.children.add_error "invalid_child" if @allows_children
69
+
70
+ errors = new_instance.errors(true)
71
+ count = @allows_children ? 2 : 1
72
+ errors.count.should eql count
73
+ errors.first.should eql "invalid"
74
+ errors.last.should eql "invalid_child" if @allows_children
75
+ end
76
+
77
+ it "should include child errors if include_child_errors isn't specified" do
78
+ new_instance.add_error "invalid"
79
+ new_instance.children.add_error "invalid_child" if @allows_children
80
+
81
+ errors = new_instance.errors(true)
82
+ count = @allows_children ? 2 : 1
83
+ errors.count.should eql count
84
+ errors.first.should eql "invalid"
85
+ errors.last.should eql "invalid_child" if @allows_children
86
+ end
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ SimpleCov.root File.expand_path('../../', __FILE__)
4
+ add_filter "/spec"
5
+ end
6
+
7
+ require 'rubygems'
8
+ require 'test/unit'
9
+ require 'rspec'
10
+ require 'bible_reference_parser'
11
+
12
+ # Load shared example modules
13
+ Dir["#{File.dirname(__FILE__)}/shared/*.rb"].each {|f| require f}
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+
3
+ include BibleReferenceParser
4
+
5
+ describe VerseReference do
6
+
7
+ it_should_behave_like "it tracks errors", VerseReference.new(1), VerseReference.new(0)
8
+
9
+ describe "initialization" do
10
+ context "for a valid verse" do
11
+ it "should convert a string verse number to an integer" do
12
+ verse = VerseReference.new "10"
13
+ verse.number.should eql 10
14
+ end
15
+
16
+ it "should set the number field" do
17
+ verse = VerseReference.new 1
18
+ verse.number.should eql 1
19
+ end
20
+ end
21
+
22
+ context "for an invalid verse" do
23
+ it "should add an error for a number less than 0" do
24
+ verse = VerseReference.new -1
25
+ verse.errors.first.should eql "The verse number '-1' is not valid"
26
+ end
27
+
28
+ it "should add an error for a number equal to 0" do
29
+ verse = VerseReference.new 0
30
+ verse.errors.first.should eql "The verse number '0' is not valid"
31
+ end
32
+
33
+ it "should add an error if the verse is not valid for a book/chapter" do
34
+ verse = VerseReference.new 18, BibleMetadata["Matthew"], 3
35
+ verse.errors.first.should eql "The verse '18' does not exist for Matthew 3"
36
+ end
37
+
38
+ it "should not set the number field" do
39
+ verse = VerseReference.new 0
40
+ verse.number.should be_nil
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "the valid_reference? method" do
46
+ it "should return true if the verse number is valid" do
47
+ verse = VerseReference.new 1
48
+ verse.should be_valid_reference
49
+ end
50
+
51
+ it "should return false if the verse is invalid" do
52
+ verse = VerseReference.new 0
53
+ verse.should_not be_valid_reference
54
+ end
55
+ end
56
+
57
+ describe "when parsing the verses in a string" do
58
+
59
+ describe "the parse_verses method" do
60
+ it "should parse single verses" do
61
+ verses = VerseReference.parse_verses "1, 2,3"
62
+ verses.length.should eql 3
63
+ verses[0].number.should eql 1
64
+ verses[1].number.should eql 2
65
+ verses[2].number.should eql 3
66
+ end
67
+
68
+ it "should parse single verses that has semi-colons instead of commas" do
69
+ verses = VerseReference.parse_verses "1;2; 3"
70
+ verses.length.should eql 3
71
+ verses[0].number.should eql 1
72
+ verses[1].number.should eql 2
73
+ verses[2].number.should eql 3
74
+ end
75
+
76
+ it "should parse a range of verses" do
77
+ verses = VerseReference.parse_verses "1-5"
78
+ verses.length.should eql 5
79
+ verses[0].number.should eql 1
80
+ verses[1].number.should eql 2
81
+ verses[2].number.should eql 3
82
+ verses[3].number.should eql 4
83
+ verses[4].number.should eql 5
84
+ end
85
+
86
+ it "should parse a combination of ranges and single verses" do
87
+ verses = VerseReference.parse_verses "1, 2, 5-7 ;9, 11, 15-17"
88
+ verses.length.should eql 10
89
+ verses[0].number.should eql 1
90
+ verses[1].number.should eql 2
91
+ verses[2].number.should eql 5
92
+ verses[3].number.should eql 6
93
+ verses[4].number.should eql 7
94
+ verses[5].number.should eql 9
95
+ verses[6].number.should eql 11
96
+ verses[7].number.should eql 15
97
+ verses[8].number.should eql 16
98
+ verses[9].number.should eql 17
99
+ end
100
+
101
+ it "should parse a string beginning and ending with a range" do
102
+ verses = VerseReference.parse_verses "1-3, 5, 7-8"
103
+ verses.length.should eql 6
104
+ verses[0].number.should eql 1
105
+ verses[1].number.should eql 2
106
+ verses[2].number.should eql 3
107
+ verses[3].number.should eql 5
108
+ verses[4].number.should eql 7
109
+ verses[5].number.should eql 8
110
+ end
111
+
112
+ it "should parse a string beginning and ending with a single verse" do
113
+ verses = VerseReference.parse_verses "1, 3-4, 7"
114
+ verses.length.should eql 4
115
+ verses[0].number.should eql 1
116
+ verses[1].number.should eql 3
117
+ verses[2].number.should eql 4
118
+ verses[3].number.should eql 7
119
+ end
120
+
121
+ it "should parse a range that has the same beginning and end" do
122
+ verses = VerseReference.parse_verses "1, 7-7"
123
+ verses.length.should eql 2
124
+ verses[0].number.should eql 1
125
+ verses[1].number.should eql 7
126
+ end
127
+ end
128
+
129
+ describe "the parse_verses_in_reference method" do
130
+ before :each do
131
+ @chapter = ChapterReference.new "1", "1, 3-5"
132
+ @verses = VerseReference.parse_verses_in_reference @chapter
133
+ end
134
+
135
+ it "should parse the right raw_content" do
136
+ @verses.first.number.should eql 1
137
+ @verses.last.number.should eql 5
138
+ end
139
+
140
+ it "should assume all verses for a chapter with nil raw_content and chapter metadata isn't nil" do
141
+ chapter = ChapterReference.new 1, nil, BibleMetadata["Matthew"]
142
+ verses = VerseReference.parse_verses_in_reference chapter
143
+ verses.length.should eql 25
144
+ end
145
+
146
+ it "should assume just the first verse for a chapter with nil raw_content and chapter metadata is nil" do
147
+ chapter = ChapterReference.new 1, nil
148
+ verses = VerseReference.parse_verses_in_reference chapter
149
+ verses.length.should eql 1
150
+ end
151
+ end
152
+
153
+ describe "each returned verse" do
154
+ it "should correctly set the number attribute" do
155
+ verses = VerseReference.parse_verses "1-3"
156
+ verses.first.number.should eql 1
157
+ end
158
+ end
159
+
160
+ describe "the returned value" do
161
+ it "should be a reference collection" do
162
+ verses = VerseReference.parse_verses("1-10, 15")
163
+ verses.should be_kind_of ReferenceCollection
164
+ end
165
+
166
+ it "should only contain VerseReference objects" do
167
+ verses = VerseReference.parse_verses("1-10, 15")
168
+ verses.each do |verse|
169
+ verse.should be_kind_of VerseReference
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+
176
+ describe "the 'clean' method" do
177
+ it "should return an empty array" do
178
+ verse = VerseReference.new 1
179
+ verse.clean.should eql []
180
+ end
181
+ end
182
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bible_reference_parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Nathan McWilliams
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-29 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 0
31
+ - beta
32
+ - 19
33
+ version: 2.0.0.beta.19
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: simplecov
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ - 3
47
+ - 2
48
+ version: 0.3.2
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: *id002
52
+ description: BibleReferenceParser can parse scriptures passages, such as 'Gen. 1:15-18, 21' to the individual books, chapters and verses in the passage. It also provides validation for invalid book names, chapters, and verses.
53
+ email: nathan.mcwilliams@gmail.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - LICENSE
60
+ - README.markdown
61
+ files:
62
+ - .document
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE
68
+ - README.markdown
69
+ - Rakefile
70
+ - VERSION
71
+ - bible_reference_parser.gemspec
72
+ - lib/bible_reference_parser.rb
73
+ - lib/bible_reference_parser/metadata/bible_metadata.rb
74
+ - lib/bible_reference_parser/metadata/metadata.yml
75
+ - lib/bible_reference_parser/parser.rb
76
+ - lib/bible_reference_parser/reference/behavior/tracks_errors.rb
77
+ - lib/bible_reference_parser/reference/book_reference.rb
78
+ - lib/bible_reference_parser/reference/chapter_reference.rb
79
+ - lib/bible_reference_parser/reference/reference_collection.rb
80
+ - lib/bible_reference_parser/reference/verse_reference.rb
81
+ - spec/bible_metadata_spec.rb
82
+ - spec/book_reference_spec.rb
83
+ - spec/chapter_reference_spec.rb
84
+ - spec/parser_spec.rb
85
+ - spec/reference_collection_spec.rb
86
+ - spec/shared/it_tracks_errors_shared.rb
87
+ - spec/spec_helper.rb
88
+ - spec/verse_reference_spec.rb
89
+ has_rdoc: true
90
+ homepage: http://github.com/endium/bible_reference_parser
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options:
95
+ - --charset=UTF-8
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 4012488893589496210
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Parsing and validation for scripture passages.
122
+ test_files:
123
+ - spec/bible_metadata_spec.rb
124
+ - spec/book_reference_spec.rb
125
+ - spec/chapter_reference_spec.rb
126
+ - spec/parser_spec.rb
127
+ - spec/reference_collection_spec.rb
128
+ - spec/shared/it_tracks_errors_shared.rb
129
+ - spec/spec_helper.rb
130
+ - spec/verse_reference_spec.rb