cskit 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -4
  3. data/History.txt +5 -0
  4. data/cskit.gemspec +5 -8
  5. data/lib/cskit.rb +15 -66
  6. data/lib/cskit/annotated_string.rb +1 -1
  7. data/lib/cskit/annotator.rb +1 -3
  8. data/lib/cskit/formatters.rb +3 -4
  9. data/lib/cskit/formatters/bible.rb +4 -5
  10. data/lib/cskit/formatters/bible/bible_html_formatter.rb +2 -2
  11. data/lib/cskit/formatters/bible/bible_json_formatter.rb +17 -0
  12. data/lib/cskit/formatters/bible/bible_plain_text_formatter.rb +3 -3
  13. data/lib/cskit/formatters/science_health.rb +3 -5
  14. data/lib/cskit/formatters/science_health/science_health_html_formatter.rb +3 -4
  15. data/lib/cskit/formatters/science_health/science_health_plain_text_formatter.rb +5 -4
  16. data/lib/cskit/lesson.rb +3 -5
  17. data/lib/cskit/lesson/lesson.rb +3 -3
  18. data/lib/cskit/lesson/section.rb +1 -1
  19. data/lib/cskit/parsers.rb +6 -3
  20. data/lib/cskit/parsers/bible.rb +10 -0
  21. data/lib/cskit/parsers/bible/bible_parser.rb +192 -0
  22. data/lib/cskit/parsers/bible/bible_tokenizer.rb +32 -0
  23. data/lib/cskit/parsers/parser.rb +68 -0
  24. data/lib/cskit/parsers/science_health.rb +10 -0
  25. data/lib/cskit/parsers/science_health/science_health_parser.rb +201 -0
  26. data/lib/cskit/parsers/science_health/science_health_tokenizer.rb +33 -0
  27. data/lib/cskit/parsers/token.rb +17 -0
  28. data/lib/cskit/parsers/tokenizer.rb +43 -0
  29. data/lib/cskit/readers.rb +4 -4
  30. data/lib/cskit/readers/bible_reader.rb +2 -2
  31. data/lib/cskit/readers/reading.rb +8 -1
  32. data/lib/cskit/readers/science_health_reader.rb +8 -8
  33. data/lib/cskit/registry.rb +65 -0
  34. data/lib/cskit/resources/volumes.rb +3 -3
  35. data/lib/cskit/resources/volumes/bible.rb +11 -9
  36. data/lib/cskit/resources/volumes/science_health.rb +10 -9
  37. data/lib/cskit/version.rb +1 -1
  38. data/lib/cskit/volume.rb +1 -1
  39. data/spec/parsers/bible/bible_parser_spec.rb +205 -0
  40. data/spec/parsers/science_health/science_health_parser_spec.rb +153 -0
  41. data/spec/spec_helper.rb +8 -0
  42. metadata +16 -38
  43. data/lib/cskit/parsers/bible/bible.rb +0 -1005
  44. data/lib/cskit/parsers/bible/bible.treetop +0 -64
  45. data/lib/cskit/parsers/bible/nodes.rb +0 -153
  46. data/lib/cskit/parsers/bible/objects.rb +0 -81
  47. data/lib/cskit/parsers/science_health/nodes.rb +0 -82
  48. data/lib/cskit/parsers/science_health/objects.rb +0 -47
  49. data/lib/cskit/parsers/science_health/science_health.rb +0 -607
  50. data/lib/cskit/parsers/science_health/science_health.treetop +0 -44
@@ -15,6 +15,13 @@ module CSKit
15
15
  def annotated?
16
16
  false
17
17
  end
18
+
19
+ def to_hash
20
+ {
21
+ texts: texts,
22
+ chapter: chapter.to_hash
23
+ }
24
+ end
18
25
  end
19
26
 
20
27
  class AnnotatedReading < Reading
@@ -51,4 +58,4 @@ module CSKit
51
58
  end
52
59
 
53
60
  end
54
- end
61
+ end
@@ -3,6 +3,7 @@
3
3
  module CSKit
4
4
  module Readers
5
5
  class ScienceHealthReader
6
+ NUMERALS = %w(vi vii ix x xi xii)
6
7
 
7
8
  attr_reader :volume
8
9
 
@@ -95,7 +96,7 @@ module CSKit
95
96
  end
96
97
  end
97
98
 
98
- protected
99
+ private
99
100
 
100
101
  def increment(line_number, page_number)
101
102
  page = get_page(page_number)
@@ -107,16 +108,15 @@ module CSKit
107
108
  end
108
109
 
109
110
  def next_page_number(page_number)
110
- numerals = ["vi", "vii", "ix", "x", "xi", "xii"]
111
- if index = numerals.index(page_number)
112
- if index == numerals.size - 1
113
- "1"
111
+ if index = NUMERALS.index(page_number)
112
+ if index == NUMERALS.size - 1
113
+ '1'
114
114
  else
115
- numerals[index + 1]
115
+ NUMERALS[index + 1]
116
116
  end
117
117
  else
118
- if page_number == "497"
119
- "501"
118
+ if page_number == '497'
119
+ '501'
120
120
  else
121
121
  (page_number.to_i + 1).to_s
122
122
  end
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Registry
5
+ def family(family, plural_family)
6
+ extend RegistryFactory.create(family, plural_family)
7
+ end
8
+
9
+ def registry
10
+ @registry ||= {}
11
+ end
12
+ end
13
+
14
+ class RegistryFactory
15
+ class << self
16
+
17
+ def create(family, plural_family)
18
+ Module.new do
19
+ define_method :"register_#{family}" do |config|
20
+ register(family, config[:id], config[family].new(config))
21
+ end
22
+
23
+ define_method :"get_#{family}" do |id|
24
+ get(family, id)
25
+ end
26
+
27
+ define_method :"#{plural_family}" do
28
+ all(family)
29
+ end
30
+
31
+ define_method :"#{family}_available?" do |id|
32
+ available?(family, id)
33
+ end
34
+
35
+ private
36
+
37
+ def register(family, key, obj)
38
+ (registry[family.to_sym] ||= {})[key.to_sym] = obj
39
+ end
40
+
41
+ def get(family, key)
42
+ registry[family.to_sym][key.to_sym] || get_for_family(family, key)
43
+ end
44
+
45
+ def all(family)
46
+ registry.fetch(family, [])
47
+ end
48
+
49
+ def get_for_family(family, type)
50
+ found = registry[family.to_sym].find do |key, obj|
51
+ obj.config[:type] == type
52
+ end
53
+
54
+ found.last if found
55
+ end
56
+
57
+ def available?(family, key)
58
+ !!registry[family.to_sym][key.to_sym] rescue false
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module CSKit
4
4
  module Volumes
5
- autoload :ScienceHealth, "cskit/resources/volumes/science_health"
6
- autoload :Bible, "cskit/resources/volumes/bible"
5
+ autoload :ScienceHealth, 'cskit/resources/volumes/science_health'
6
+ autoload :Bible, 'cskit/resources/volumes/bible'
7
7
  end
8
- end
8
+ end
@@ -6,40 +6,42 @@ module CSKit
6
6
 
7
7
  Book = Struct.new(:name, :chapters) do
8
8
  def to_hash
9
- { "name" => name, "chapters" => chapters.map(&:to_hash) }
9
+ { 'name' => name, 'chapters' => chapters.map(&:to_hash) }
10
10
  end
11
11
 
12
12
  def self.from_hash(hash)
13
13
  Book.new(
14
- hash["name"],
15
- hash["chapters"].map { |chapter_hash| Chapter.from_hash(chapter_hash) }
14
+ hash['name'],
15
+ hash['chapters'].map do |chapter_hash|
16
+ Chapter.from_hash(chapter_hash)
17
+ end
16
18
  )
17
19
  end
18
20
  end
19
21
 
20
22
  Chapter = Struct.new(:number, :verses) do
21
23
  def to_hash
22
- { "number" => number, "verses" => verses.map(&:to_hash) }
24
+ { 'number' => number, 'verses' => verses.map(&:to_hash) }
23
25
  end
24
26
 
25
27
  def self.from_hash(hash)
26
28
  Chapter.new(
27
- hash["number"],
28
- hash["verses"].map { |verse_hash| Verse.from_hash(verse_hash) }
29
+ hash['number'],
30
+ hash['verses'].map { |verse_hash| Verse.from_hash(verse_hash) }
29
31
  )
30
32
  end
31
33
  end
32
34
 
33
35
  Verse = Struct.new(:text) do
34
36
  def to_hash
35
- { "text" => text }
37
+ { 'text' => text }
36
38
  end
37
39
 
38
40
  def self.from_hash(hash)
39
- Verse.new(hash["text"])
41
+ Verse.new(hash['text'])
40
42
  end
41
43
  end
42
44
 
43
45
  end
44
46
  end
45
- end
47
+ end
@@ -10,13 +10,13 @@ module CSKit
10
10
  end
11
11
 
12
12
  def to_hash
13
- { "number" => number, "lines" => lines.map(&:to_hash) }
13
+ { 'number' => number, 'lines' => lines.map(&:to_hash) }
14
14
  end
15
15
 
16
16
  def self.from_hash(hash)
17
17
  Page.new(
18
- hash["number"],
19
- hash["lines"].map { |line_hash| Line.from_hash(line_hash) }
18
+ hash['number'],
19
+ hash['lines'].map { |line_hash| Line.from_hash(line_hash) }
20
20
  )
21
21
  end
22
22
  end
@@ -29,17 +29,18 @@ module CSKit
29
29
  alias :paragraph_start? :paragraph_start
30
30
 
31
31
  def to_hash
32
- { "text" => text,
33
- "flyout_text" => flyout_text,
34
- "paragraph_start" => paragraph_start
32
+ {
33
+ 'text' => text,
34
+ 'flyout_text' => flyout_text,
35
+ 'paragraph_start' => paragraph_start
35
36
  }
36
37
  end
37
38
 
38
39
  def self.from_hash(hash)
39
40
  Line.new(
40
- hash["text"],
41
- hash["flyout_text"],
42
- !!hash["paragraph_start"]
41
+ hash['text'],
42
+ hash['flyout_text'],
43
+ !!hash['paragraph_start']
43
44
  )
44
45
  end
45
46
  end
data/lib/cskit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module CSKit
4
- VERSION = "1.0.1"
4
+ VERSION = '1.1.0'
5
5
  end
data/lib/cskit/volume.rb CHANGED
@@ -30,4 +30,4 @@ module CSKit
30
30
  end
31
31
 
32
32
  end
33
- end
33
+ end
@@ -0,0 +1,205 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include CSKit::Parsers::Bible
6
+
7
+ describe BibleParser do
8
+ let(:parser) { described_class.new(citation_text) }
9
+
10
+ context 'single chapter, single verse' do
11
+ let(:citation_text) { 'Genesis 1:1' }
12
+
13
+ it 'parses correctly' do
14
+ expect(parser.parse.to_hash).to eq({
15
+ book: 'Genesis', chapters: [{
16
+ chapter_number: 1, verses: [{
17
+ start: 1, finish: 1, starter: nil, terminator: nil
18
+ }]
19
+ }]
20
+ })
21
+ end
22
+ end
23
+
24
+ context 'single chapter, verse range' do
25
+ let(:citation_text) { 'Genesis 1:1-5' }
26
+
27
+ it 'parses correctly' do
28
+ expect(parser.parse.to_hash).to eq({
29
+ book: 'Genesis', chapters: [{
30
+ chapter_number: 1, verses: [{
31
+ start: 1, finish: 5, starter: nil, terminator: nil
32
+ }]
33
+ }]
34
+ })
35
+ end
36
+ end
37
+
38
+ context 'single chapter, verse range, starter fragment' do
39
+ let(:citation_text) { 'Genesis 1:1-5 God' }
40
+
41
+ it 'parses correctly' do
42
+ expect(parser.parse.to_hash).to eq({
43
+ book: 'Genesis', chapters: [{
44
+ chapter_number: 1, verses: [{
45
+ start: 1, finish: 5, terminator: nil, starter: {
46
+ fragment: 'God', cardinality: 1
47
+ }
48
+ }]
49
+ }]
50
+ })
51
+ end
52
+ end
53
+
54
+ context 'single chapter, verse range, starter fragment with cardinality' do
55
+ let(:citation_text) { 'Genesis 1:1-5 2nd God' }
56
+
57
+ it 'parses correctly' do
58
+ expect(parser.parse.to_hash).to eq({
59
+ book: 'Genesis', chapters: [{
60
+ chapter_number: 1, verses: [{
61
+ start: 1, finish: 5, terminator: nil, starter: {
62
+ fragment: 'God', cardinality: 2
63
+ }
64
+ }]
65
+ }]
66
+ })
67
+ end
68
+ end
69
+
70
+ context 'single chapter, single verse, starter fragment with cardinality' do
71
+ let(:citation_text) { 'Genesis 1:1 2nd God' }
72
+
73
+ it 'parses correctly' do
74
+ expect(parser.parse.to_hash).to eq({
75
+ book: 'Genesis', chapters: [{
76
+ chapter_number: 1, verses: [{
77
+ start: 1, finish: 1, terminator: nil, starter: {
78
+ fragment: 'God', cardinality: 2
79
+ }
80
+ }]
81
+ }]
82
+ })
83
+ end
84
+ end
85
+
86
+ context 'single chapter, single verse, starter fragment, terminator fragment' do
87
+ let(:citation_text) { 'Genesis 1:1 God (to said)' }
88
+
89
+ it 'parses correctly' do
90
+ expect(parser.parse.to_hash).to eq({
91
+ book: 'Genesis', chapters: [{
92
+ chapter_number: 1, verses: [{
93
+ start: 1, finish: 1, terminator: {
94
+ fragment: 'said', cardinality: 1
95
+ }, starter: {
96
+ fragment: 'God', cardinality: 1
97
+ }
98
+ }]
99
+ }]
100
+ })
101
+ end
102
+ end
103
+
104
+ context 'single chapter, single verse, starter fragment, terminator fragment with cardinality' do
105
+ let(:citation_text) { 'Genesis 1:1 God (to 2nd said)' }
106
+
107
+ it 'parses correctly' do
108
+ expect(parser.parse.to_hash).to eq({
109
+ book: 'Genesis', chapters: [{
110
+ chapter_number: 1, verses: [{
111
+ start: 1, finish: 1, terminator: {
112
+ fragment: 'said', cardinality: 2
113
+ }, starter: {
114
+ fragment: 'God', cardinality: 1
115
+ }
116
+ }]
117
+ }]
118
+ })
119
+ end
120
+ end
121
+
122
+ context 'single chapter, single verse, starter fragment with cardinality, terminator fragment with cardinality' do
123
+ let(:citation_text) { 'Genesis 1:1 3rd God (to 2nd said)' }
124
+
125
+ it 'parses correctly' do
126
+ expect(parser.parse.to_hash).to eq({
127
+ book: 'Genesis', chapters: [{
128
+ chapter_number: 1, verses: [{
129
+ start: 1, finish: 1, terminator: {
130
+ fragment: 'said', cardinality: 2
131
+ }, starter: {
132
+ fragment: 'God', cardinality: 3
133
+ }
134
+ }]
135
+ }]
136
+ })
137
+ end
138
+ end
139
+
140
+ context 'multiple chapters, single verse' do
141
+ let(:citation_text) { 'Genesis 1:1; 4:8' }
142
+
143
+ it 'parses correctly' do
144
+ expect(parser.parse.to_hash).to eq({
145
+ book: 'Genesis', chapters: [{
146
+ chapter_number: 1, verses: [{
147
+ start: 1, finish: 1, terminator: nil, starter: nil
148
+ }]
149
+ }, {
150
+ chapter_number: 4, verses: [{
151
+ start: 8, finish: 8, terminator: nil, starter: nil
152
+ }]
153
+ }]
154
+ })
155
+ end
156
+ end
157
+
158
+ context 'multiple chapters, single and multiple verses' do
159
+ let(:citation_text) { 'Genesis 1:1; 4:8, 9-12' }
160
+
161
+ it 'parses correctly' do
162
+ expect(parser.parse.to_hash).to eq({
163
+ book: 'Genesis', chapters: [{
164
+ chapter_number: 1, verses: [{
165
+ start: 1, finish: 1, terminator: nil, starter: nil
166
+ }]
167
+ }, {
168
+ chapter_number: 4, verses: [{
169
+ start: 8, finish: 8, terminator: nil, starter: nil
170
+ }, {
171
+ start: 9, finish: 12, terminator: nil, starter: nil
172
+ }]
173
+ }]
174
+ })
175
+ end
176
+ end
177
+
178
+ context 'multiple chapters, verses with terminators' do
179
+ let(:citation_text) { 'Genesis 1:1; 4:8 great (to 2nd ;), 9-12 2nd not (to 3rd ,)' }
180
+
181
+ it 'parses correctly' do
182
+ expect(parser.parse.to_hash).to eq({
183
+ book: 'Genesis', chapters: [{
184
+ chapter_number: 1, verses: [{
185
+ start: 1, finish: 1, terminator: nil, starter: nil
186
+ }]
187
+ }, {
188
+ chapter_number: 4, verses: [{
189
+ start: 8, finish: 8, terminator: {
190
+ fragment: ';', cardinality: 2
191
+ }, starter: {
192
+ fragment: 'great', cardinality: 1
193
+ }
194
+ }, {
195
+ start: 9, finish: 12, terminator: {
196
+ fragment: ',', cardinality: 3
197
+ }, starter: {
198
+ fragment: 'not', cardinality: 2
199
+ }
200
+ }]
201
+ }]
202
+ })
203
+ end
204
+ end
205
+ end