cskit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +8 -0
  3. data/History.txt +3 -0
  4. data/LICENSE +177 -0
  5. data/README.md +246 -0
  6. data/Rakefile +29 -0
  7. data/cskit.gemspec +25 -0
  8. data/lib/cskit/annotated_string.rb +73 -0
  9. data/lib/cskit/annotator.rb +16 -0
  10. data/lib/cskit/formatters/bible/bible_html_formatter.rb +41 -0
  11. data/lib/cskit/formatters/bible/bible_plain_text_formatter.rb +117 -0
  12. data/lib/cskit/formatters/bible.rb +12 -0
  13. data/lib/cskit/formatters/science_health/science_health_html_formatter.rb +32 -0
  14. data/lib/cskit/formatters/science_health/science_health_plain_text_formatter.rb +73 -0
  15. data/lib/cskit/formatters/science_health.rb +12 -0
  16. data/lib/cskit/formatters.rb +19 -0
  17. data/lib/cskit/lesson/lesson.rb +72 -0
  18. data/lib/cskit/lesson/section.rb +26 -0
  19. data/lib/cskit/lesson.rb +10 -0
  20. data/lib/cskit/parsers/bible/bible.rb +1005 -0
  21. data/lib/cskit/parsers/bible/bible.treetop +64 -0
  22. data/lib/cskit/parsers/bible/nodes.rb +153 -0
  23. data/lib/cskit/parsers/bible/objects.rb +81 -0
  24. data/lib/cskit/parsers/science_health/nodes.rb +82 -0
  25. data/lib/cskit/parsers/science_health/objects.rb +47 -0
  26. data/lib/cskit/parsers/science_health/science_health.rb +607 -0
  27. data/lib/cskit/parsers/science_health/science_health.treetop +44 -0
  28. data/lib/cskit/parsers.rb +8 -0
  29. data/lib/cskit/readers/bible_reader.rb +58 -0
  30. data/lib/cskit/readers/reading.rb +54 -0
  31. data/lib/cskit/readers/science_health_reader.rb +97 -0
  32. data/lib/cskit/readers.rb +9 -0
  33. data/lib/cskit/resources/volumes/bible.rb +45 -0
  34. data/lib/cskit/resources/volumes/science_health.rb +49 -0
  35. data/lib/cskit/resources/volumes.rb +8 -0
  36. data/lib/cskit/version.rb +5 -0
  37. data/lib/cskit/volume.rb +33 -0
  38. data/lib/cskit.rb +73 -0
  39. metadata +122 -0
@@ -0,0 +1,607 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ # encoding: UTF-8
5
+
6
+ require 'cskit/parsers/science_health/nodes'
7
+ require 'cskit/parsers/science_health/objects'
8
+
9
+ module CSKit
10
+ module Parsers
11
+
12
+ module ScienceHealth
13
+ include Treetop::Runtime
14
+
15
+ def root
16
+ @root ||= :citation
17
+ end
18
+
19
+ module Citation0
20
+ def page
21
+ elements[0]
22
+ end
23
+
24
+ def line_list
25
+ elements[4]
26
+ end
27
+ end
28
+
29
+ def _nt_citation
30
+ start_index = index
31
+ if node_cache[:citation].has_key?(index)
32
+ cached = node_cache[:citation][index]
33
+ if cached
34
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
35
+ @index = cached.interval.end
36
+ end
37
+ return cached
38
+ end
39
+
40
+ i0, s0 = index, []
41
+ r1 = _nt_page
42
+ s0 << r1
43
+ if r1
44
+ s2, i2 = [], index
45
+ loop do
46
+ if has_terminal?('\G[\\s]', true, index)
47
+ r3 = true
48
+ @index += 1
49
+ else
50
+ r3 = nil
51
+ end
52
+ if r3
53
+ s2 << r3
54
+ else
55
+ break
56
+ end
57
+ end
58
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
59
+ s0 << r2
60
+ if r2
61
+ if has_terminal?(":", false, index)
62
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
63
+ @index += 1
64
+ else
65
+ terminal_parse_failure(":")
66
+ r4 = nil
67
+ end
68
+ s0 << r4
69
+ if r4
70
+ s5, i5 = [], index
71
+ loop do
72
+ if has_terminal?('\G[\\s]', true, index)
73
+ r6 = true
74
+ @index += 1
75
+ else
76
+ r6 = nil
77
+ end
78
+ if r6
79
+ s5 << r6
80
+ else
81
+ break
82
+ end
83
+ end
84
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
85
+ s0 << r5
86
+ if r5
87
+ r7 = _nt_line_list
88
+ s0 << r7
89
+ end
90
+ end
91
+ end
92
+ end
93
+ if s0.last
94
+ r0 = instantiate_node(CitationNode,input, i0...index, s0)
95
+ r0.extend(Citation0)
96
+ else
97
+ @index = i0
98
+ r0 = nil
99
+ end
100
+
101
+ node_cache[:citation][start_index] = r0
102
+
103
+ r0
104
+ end
105
+
106
+ def _nt_page
107
+ start_index = index
108
+ if node_cache[:page].has_key?(index)
109
+ cached = node_cache[:page][index]
110
+ if cached
111
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
112
+ @index = cached.interval.end
113
+ end
114
+ return cached
115
+ end
116
+
117
+ s0, i0 = [], index
118
+ loop do
119
+ if has_terminal?('\G[\\d{1,3}|vi{2}|xi{1,2}|i{0,1}x]', true, index)
120
+ r1 = true
121
+ @index += 1
122
+ else
123
+ r1 = nil
124
+ end
125
+ if r1
126
+ s0 << r1
127
+ else
128
+ break
129
+ end
130
+ end
131
+ if s0.empty?
132
+ @index = i0
133
+ r0 = nil
134
+ else
135
+ r0 = instantiate_node(PageNode,input, i0...index, s0)
136
+ end
137
+
138
+ node_cache[:page][start_index] = r0
139
+
140
+ r0
141
+ end
142
+
143
+ module LineList0
144
+ def line_list
145
+ elements[3]
146
+ end
147
+ end
148
+
149
+ module LineList1
150
+ def line
151
+ elements[0]
152
+ end
153
+
154
+ end
155
+
156
+ def _nt_line_list
157
+ start_index = index
158
+ if node_cache[:line_list].has_key?(index)
159
+ cached = node_cache[:line_list][index]
160
+ if cached
161
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
162
+ @index = cached.interval.end
163
+ end
164
+ return cached
165
+ end
166
+
167
+ i0, s0 = index, []
168
+ r1 = _nt_line
169
+ s0 << r1
170
+ if r1
171
+ i3, s3 = index, []
172
+ s4, i4 = [], index
173
+ loop do
174
+ if has_terminal?('\G[\\s]', true, index)
175
+ r5 = true
176
+ @index += 1
177
+ else
178
+ r5 = nil
179
+ end
180
+ if r5
181
+ s4 << r5
182
+ else
183
+ break
184
+ end
185
+ end
186
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
187
+ s3 << r4
188
+ if r4
189
+ if has_terminal?(",", false, index)
190
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
191
+ @index += 1
192
+ else
193
+ terminal_parse_failure(",")
194
+ r6 = nil
195
+ end
196
+ s3 << r6
197
+ if r6
198
+ s7, i7 = [], index
199
+ loop do
200
+ if has_terminal?('\G[\\s]', true, index)
201
+ r8 = true
202
+ @index += 1
203
+ else
204
+ r8 = nil
205
+ end
206
+ if r8
207
+ s7 << r8
208
+ else
209
+ break
210
+ end
211
+ end
212
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
213
+ s3 << r7
214
+ if r7
215
+ r9 = _nt_line_list
216
+ s3 << r9
217
+ end
218
+ end
219
+ end
220
+ if s3.last
221
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
222
+ r3.extend(LineList0)
223
+ else
224
+ @index = i3
225
+ r3 = nil
226
+ end
227
+ if r3
228
+ r2 = r3
229
+ else
230
+ r2 = instantiate_node(SyntaxNode,input, index...index)
231
+ end
232
+ s0 << r2
233
+ end
234
+ if s0.last
235
+ r0 = instantiate_node(LineListNode,input, i0...index, s0)
236
+ r0.extend(LineList1)
237
+ else
238
+ @index = i0
239
+ r0 = nil
240
+ end
241
+
242
+ node_cache[:line_list][start_index] = r0
243
+
244
+ r0
245
+ end
246
+
247
+ module Line0
248
+ end
249
+
250
+ def _nt_line
251
+ start_index = index
252
+ if node_cache[:line].has_key?(index)
253
+ cached = node_cache[:line][index]
254
+ if cached
255
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
256
+ @index = cached.interval.end
257
+ end
258
+ return cached
259
+ end
260
+
261
+ i0, s0 = index, []
262
+ i1 = index
263
+ r2 = _nt_compound_line_number
264
+ if r2
265
+ r1 = r2
266
+ else
267
+ r3 = _nt_line_number
268
+ if r3
269
+ r1 = r3
270
+ else
271
+ @index = i1
272
+ r1 = nil
273
+ end
274
+ end
275
+ s0 << r1
276
+ if r1
277
+ i5 = index
278
+ r6 = _nt_only
279
+ if r6
280
+ r5 = r6
281
+ else
282
+ r7 = _nt_start_fragment
283
+ if r7
284
+ r5 = r7
285
+ else
286
+ @index = i5
287
+ r5 = nil
288
+ end
289
+ end
290
+ if r5
291
+ r4 = r5
292
+ else
293
+ r4 = instantiate_node(SyntaxNode,input, index...index)
294
+ end
295
+ s0 << r4
296
+ end
297
+ if s0.last
298
+ r0 = instantiate_node(LineNode,input, i0...index, s0)
299
+ r0.extend(Line0)
300
+ else
301
+ @index = i0
302
+ r0 = nil
303
+ end
304
+
305
+ node_cache[:line][start_index] = r0
306
+
307
+ r0
308
+ end
309
+
310
+ module CompoundLineNumber0
311
+ def line_number1
312
+ elements[0]
313
+ end
314
+
315
+ def line_number2
316
+ elements[4]
317
+ end
318
+ end
319
+
320
+ def _nt_compound_line_number
321
+ start_index = index
322
+ if node_cache[:compound_line_number].has_key?(index)
323
+ cached = node_cache[:compound_line_number][index]
324
+ if cached
325
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
326
+ @index = cached.interval.end
327
+ end
328
+ return cached
329
+ end
330
+
331
+ i0, s0 = index, []
332
+ r1 = _nt_line_number
333
+ s0 << r1
334
+ if r1
335
+ s2, i2 = [], index
336
+ loop do
337
+ if has_terminal?('\G[\\s]', true, index)
338
+ r3 = true
339
+ @index += 1
340
+ else
341
+ r3 = nil
342
+ end
343
+ if r3
344
+ s2 << r3
345
+ else
346
+ break
347
+ end
348
+ end
349
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
350
+ s0 << r2
351
+ if r2
352
+ if has_terminal?("-", false, index)
353
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
354
+ @index += 1
355
+ else
356
+ terminal_parse_failure("-")
357
+ r4 = nil
358
+ end
359
+ s0 << r4
360
+ if r4
361
+ s5, i5 = [], index
362
+ loop do
363
+ if has_terminal?('\G[\\s]', true, index)
364
+ r6 = true
365
+ @index += 1
366
+ else
367
+ r6 = nil
368
+ end
369
+ if r6
370
+ s5 << r6
371
+ else
372
+ break
373
+ end
374
+ end
375
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
376
+ s0 << r5
377
+ if r5
378
+ r7 = _nt_line_number
379
+ s0 << r7
380
+ end
381
+ end
382
+ end
383
+ end
384
+ if s0.last
385
+ r0 = instantiate_node(CompoundLineNumberNode,input, i0...index, s0)
386
+ r0.extend(CompoundLineNumber0)
387
+ else
388
+ @index = i0
389
+ r0 = nil
390
+ end
391
+
392
+ node_cache[:compound_line_number][start_index] = r0
393
+
394
+ r0
395
+ end
396
+
397
+ def _nt_line_number
398
+ start_index = index
399
+ if node_cache[:line_number].has_key?(index)
400
+ cached = node_cache[:line_number][index]
401
+ if cached
402
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
403
+ @index = cached.interval.end
404
+ end
405
+ return cached
406
+ end
407
+
408
+ s0, i0 = [], index
409
+ loop do
410
+ if has_terminal?('\G[\\d]', true, index)
411
+ r1 = true
412
+ @index += 1
413
+ else
414
+ r1 = nil
415
+ end
416
+ if r1
417
+ s0 << r1
418
+ else
419
+ break
420
+ end
421
+ end
422
+ if s0.empty?
423
+ @index = i0
424
+ r0 = nil
425
+ else
426
+ r0 = instantiate_node(LineNumberNode,input, i0...index, s0)
427
+ end
428
+
429
+ node_cache[:line_number][start_index] = r0
430
+
431
+ r0
432
+ end
433
+
434
+ module Only0
435
+ end
436
+
437
+ def _nt_only
438
+ start_index = index
439
+ if node_cache[:only].has_key?(index)
440
+ cached = node_cache[:only][index]
441
+ if cached
442
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
443
+ @index = cached.interval.end
444
+ end
445
+ return cached
446
+ end
447
+
448
+ i0, s0 = index, []
449
+ s1, i1 = [], index
450
+ loop do
451
+ if has_terminal?('\G[\\s]', true, index)
452
+ r2 = true
453
+ @index += 1
454
+ else
455
+ r2 = nil
456
+ end
457
+ if r2
458
+ s1 << r2
459
+ else
460
+ break
461
+ end
462
+ end
463
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
464
+ s0 << r1
465
+ if r1
466
+ if has_terminal?("(", false, index)
467
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
468
+ @index += 1
469
+ else
470
+ terminal_parse_failure("(")
471
+ r3 = nil
472
+ end
473
+ s0 << r3
474
+ if r3
475
+ s4, i4 = [], index
476
+ loop do
477
+ if has_terminal?('\G[\\s]', true, index)
478
+ r5 = true
479
+ @index += 1
480
+ else
481
+ r5 = nil
482
+ end
483
+ if r5
484
+ s4 << r5
485
+ else
486
+ break
487
+ end
488
+ end
489
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
490
+ s0 << r4
491
+ if r4
492
+ if has_terminal?("only", false, index)
493
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 4))
494
+ @index += 4
495
+ else
496
+ terminal_parse_failure("only")
497
+ r6 = nil
498
+ end
499
+ s0 << r6
500
+ if r6
501
+ s7, i7 = [], index
502
+ loop do
503
+ if has_terminal?('\G[\\s]', true, index)
504
+ r8 = true
505
+ @index += 1
506
+ else
507
+ r8 = nil
508
+ end
509
+ if r8
510
+ s7 << r8
511
+ else
512
+ break
513
+ end
514
+ end
515
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
516
+ s0 << r7
517
+ if r7
518
+ if has_terminal?(")", false, index)
519
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
520
+ @index += 1
521
+ else
522
+ terminal_parse_failure(")")
523
+ r9 = nil
524
+ end
525
+ s0 << r9
526
+ if r9
527
+ s10, i10 = [], index
528
+ loop do
529
+ if has_terminal?('\G[\\s]', true, index)
530
+ r11 = true
531
+ @index += 1
532
+ else
533
+ r11 = nil
534
+ end
535
+ if r11
536
+ s10 << r11
537
+ else
538
+ break
539
+ end
540
+ end
541
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
542
+ s0 << r10
543
+ end
544
+ end
545
+ end
546
+ end
547
+ end
548
+ end
549
+ if s0.last
550
+ r0 = instantiate_node(OnlyNode,input, i0...index, s0)
551
+ r0.extend(Only0)
552
+ else
553
+ @index = i0
554
+ r0 = nil
555
+ end
556
+
557
+ node_cache[:only][start_index] = r0
558
+
559
+ r0
560
+ end
561
+
562
+ def _nt_start_fragment
563
+ start_index = index
564
+ if node_cache[:start_fragment].has_key?(index)
565
+ cached = node_cache[:start_fragment][index]
566
+ if cached
567
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
568
+ @index = cached.interval.end
569
+ end
570
+ return cached
571
+ end
572
+
573
+ s0, i0 = [], index
574
+ loop do
575
+ if has_terminal?('\G[^,]', true, index)
576
+ r1 = true
577
+ @index += 1
578
+ else
579
+ r1 = nil
580
+ end
581
+ if r1
582
+ s0 << r1
583
+ else
584
+ break
585
+ end
586
+ end
587
+ if s0.empty?
588
+ @index = i0
589
+ r0 = nil
590
+ else
591
+ r0 = instantiate_node(StartFragmentNode,input, i0...index, s0)
592
+ end
593
+
594
+ node_cache[:start_fragment][start_index] = r0
595
+
596
+ r0
597
+ end
598
+
599
+ end
600
+
601
+ class ScienceHealthParser < Treetop::Runtime::CompiledParser
602
+ include ScienceHealth
603
+ end
604
+
605
+
606
+ end
607
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cskit/parsers/science_health/nodes'
4
+ require 'cskit/parsers/science_health/objects'
5
+
6
+ module CSKit
7
+ module Parsers
8
+
9
+ grammar ScienceHealth
10
+ rule citation
11
+ page [\s]* ":" [\s]* line_list <CitationNode>
12
+ end
13
+
14
+ rule page
15
+ [\d{1,3}|vi{2}|xi{1,2}|i{0,1}x]+ <PageNode>
16
+ end
17
+
18
+ rule line_list
19
+ line ([\s]* "," [\s]* line_list)? <LineListNode>
20
+ end
21
+
22
+ rule line
23
+ (compound_line_number / line_number) (only / start_fragment)? <LineNode>
24
+ end
25
+
26
+ rule compound_line_number
27
+ line_number [\s]* "-" [\s]* line_number <CompoundLineNumberNode>
28
+ end
29
+
30
+ rule line_number
31
+ [\d]+ <LineNumberNode>
32
+ end
33
+
34
+ rule only
35
+ [\s]* "(" [\s]* "only" [\s]* ")" [\s]* <OnlyNode>
36
+ end
37
+
38
+ rule start_fragment
39
+ [^,]+ <StartFragmentNode>
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Parsers
5
+ autoload :ScienceHealthParser, "cskit/parsers/science_health/science_health"
6
+ autoload :BibleParser, "cskit/parsers/bible/bible"
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ include CSKit::Volumes
4
+
5
+ module CSKit
6
+ module Readers
7
+ class BibleReader
8
+
9
+ attr_reader :volume
10
+
11
+ def initialize(volume)
12
+ @volume = volume
13
+ end
14
+
15
+ def get_book(book_name)
16
+ converted_book_name = convert_book_name(book_name)
17
+ volume.get_book(converted_book_name)
18
+ end
19
+
20
+ def get_chapter(chapter_number, book_name)
21
+ converted_book_name = convert_book_name(book_name)
22
+ volume.get_chapter(chapter_number, converted_book_name)
23
+ end
24
+
25
+ def get_line(line_number, page_number)
26
+ get_page(page_number).lines[line_number - 1]
27
+ end
28
+
29
+ def readings_for(citation)
30
+ citation.chapter_list.flat_map do |chapter|
31
+ map_verse_texts_for(chapter, citation.book) do |texts, verse|
32
+ Reading.new(texts, citation, chapter, verse)
33
+ end
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def map_verse_texts_for(chapter, book_name)
40
+ result = []
41
+ chapter_data = get_chapter(chapter.chapter_number, book_name)
42
+ chapter.verse_list.each do |verse|
43
+ texts = []
44
+ verse.start.upto(verse.finish) do |i|
45
+ texts << chapter_data.verses[i - 1].text
46
+ end
47
+ result << (yield texts, verse)
48
+ end
49
+ result
50
+ end
51
+
52
+ def convert_book_name(book_name)
53
+ volume.unabbreviate_book_name(book_name).downcase.gsub(" ", "_")
54
+ end
55
+
56
+ end
57
+ end
58
+ end