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,64 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cskit/parsers/bible/nodes'
4
+ require 'cskit/parsers/bible/objects'
5
+
6
+ module CSKit
7
+ module Parsers
8
+
9
+ grammar Bible
10
+ rule citation
11
+ book [\s]* chapter_list <CitationNode>
12
+ end
13
+
14
+ rule chapter_list
15
+ chapter ([\s]* ";" [\s]* chapter_list)? <ChapterListNode>
16
+ end
17
+
18
+ rule book
19
+ [a-zA-Z\.\s]+ <BookNode>
20
+ end
21
+
22
+ rule chapter
23
+ [\d]+ [\s]* ":" [\s]* verse_list <ChapterNode>
24
+ end
25
+
26
+ rule verse_list
27
+ verse ([\s]* "," [\s]* verse_list)? <VerseListNode>
28
+ end
29
+
30
+ rule verse
31
+ (compound_verse_number / verse_number) [\s]* starter [\s]* terminator <VerseNode>
32
+ end
33
+
34
+ rule compound_verse_number
35
+ verse_number [\s]* "-" [\s]* verse_number <CompoundVerseNumberNode>
36
+ end
37
+
38
+ rule verse_number
39
+ [\d]+ <VerseNumberNode>
40
+ end
41
+
42
+ rule starter
43
+ (cardinality [\s]* starter_fragment <StarterNode>)?
44
+ end
45
+
46
+ rule starter_fragment
47
+ ([^\(\)\,\;]+ <FragmentNode>)?
48
+ end
49
+
50
+ rule terminator
51
+ ("(" [\s]* "to" [\s]* cardinality [\s]* terminator_fragment [\s]* ")" <TerminatorNode>)?
52
+ end
53
+
54
+ rule terminator_fragment
55
+ ([^\(\)]+ <FragmentNode>)?
56
+ end
57
+
58
+ rule cardinality
59
+ ("1st" / "2nd" / "3rd")?
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,153 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Parsers
5
+ module Bible
6
+
7
+ class CitationNode < Treetop::Runtime::SyntaxNode
8
+ def to_sexp
9
+ [[:book, book.to_sexp], [:chapters, chapter_list.to_sexp]]
10
+ end
11
+
12
+ def to_object
13
+ CSKit::Parsers::Bible::Citation.new(
14
+ book.text_value,
15
+ chapter_list.to_object
16
+ )
17
+ end
18
+ end
19
+
20
+ class BookNode < Treetop::Runtime::SyntaxNode
21
+ def to_sexp
22
+ text_value
23
+ end
24
+ end
25
+
26
+ class ChapterListNode < Treetop::Runtime::SyntaxNode
27
+ def to_sexp
28
+ result = [chapter.to_sexp]
29
+
30
+ if elements[1] && elements[1].respond_to?(:chapter_list)
31
+ result += elements[1].chapter_list.to_sexp
32
+ end
33
+
34
+ result
35
+ end
36
+
37
+ def to_object
38
+ result = [chapter.to_object]
39
+
40
+ if elements[1] && elements[1].respond_to?(:chapter_list)
41
+ result += elements[1].chapter_list.to_object
42
+ end
43
+
44
+ result
45
+ end
46
+ end
47
+
48
+ class ChapterNode < Treetop::Runtime::SyntaxNode
49
+ def text_value
50
+ super.to_i
51
+ end
52
+
53
+ def to_sexp
54
+ [text_value, verse_list.to_sexp]
55
+ end
56
+
57
+ def to_object
58
+ CSKit::Parsers::Bible::Chapter.new(
59
+ text_value,
60
+ verse_list.to_object
61
+ )
62
+ end
63
+ end
64
+
65
+ class VerseListNode < Treetop::Runtime::SyntaxNode
66
+ def to_sexp
67
+ result = [verse.to_sexp]
68
+
69
+ if elements[1] && elements[1].respond_to?(:verse_list)
70
+ result += elements[1].verse_list.to_sexp
71
+ end
72
+
73
+ result
74
+ end
75
+
76
+ def to_object
77
+ result = [verse.to_object]
78
+
79
+ if elements[1] && elements[1].respond_to?(:verse_list)
80
+ result += elements[1].verse_list.to_object
81
+ end
82
+
83
+ result
84
+ end
85
+ end
86
+
87
+ class VerseNode < Treetop::Runtime::SyntaxNode
88
+ def to_sexp
89
+ elements.flat_map { |e| e.to_sexp if e.respond_to?(:to_sexp) }
90
+ end
91
+
92
+ def to_object
93
+ line_numbers = elements[0].to_sexp.first
94
+
95
+ CSKit::Parsers::Bible::Verse.new(
96
+ line_numbers.first,
97
+ line_numbers.last,
98
+ (starter.to_object rescue nil),
99
+ (terminator.to_object rescue nil)
100
+ )
101
+ end
102
+ end
103
+
104
+ class CompoundVerseNumberNode < Treetop::Runtime::SyntaxNode
105
+ def to_sexp
106
+ [[verse_number1.text_value.to_i, verse_number2.text_value.to_i]]
107
+ end
108
+ end
109
+
110
+ class VerseNumberNode < Treetop::Runtime::SyntaxNode
111
+ def to_sexp
112
+ [[text_value.to_i, text_value.to_i]]
113
+ end
114
+ end
115
+
116
+ class PositionalNode < Treetop::Runtime::SyntaxNode
117
+ def to_sexp
118
+ [get_cardinality, fragment.value]
119
+ end
120
+
121
+ def get_cardinality
122
+ card_val = cardinality.text_value.to_i
123
+ card_val == 0 ? 1 : card_val
124
+ end
125
+
126
+ def to_object
127
+ Positional.new(get_cardinality, fragment.value)
128
+ end
129
+ end
130
+
131
+ class StarterNode < PositionalNode
132
+ def fragment
133
+ starter_fragment
134
+ end
135
+ end
136
+
137
+ class TerminatorNode < PositionalNode
138
+ def fragment
139
+ terminator_fragment
140
+ end
141
+ end
142
+
143
+ class FragmentNode < Treetop::Runtime::SyntaxNode
144
+ def value
145
+ text_value.strip
146
+ end
147
+
148
+ alias :to_sexp :value
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Parsers
5
+ module Bible
6
+
7
+ Citation = Struct.new(:book, :chapter_list) do
8
+ def to_s
9
+ "#{book.strip} #{chapter_list.map(&:to_s).join("; ")}"
10
+ end
11
+
12
+ def to_hash
13
+ {
14
+ :book => book,
15
+ :chapters => chapter_list.map(&:to_hash)
16
+ }
17
+ end
18
+ end
19
+
20
+ Chapter = Struct.new(:chapter_number, :verse_list) do
21
+ def to_s
22
+ "#{chapter_number}:#{verse_list.map(&:to_s).join(", ")}"
23
+ end
24
+
25
+ def to_hash
26
+ {
27
+ :chapter_number => chapter_number,
28
+ :verses => verse_list.map(&:to_hash)
29
+ }
30
+ end
31
+ end
32
+
33
+ Verse = Struct.new(:start, :finish, :starter, :terminator) do
34
+ def to_s
35
+ str = if start == finish
36
+ start.to_s
37
+ else
38
+ "#{start}-#{finish}"
39
+ end
40
+
41
+ str << " #{starter}" if starter
42
+ str << " (to #{terminator})" if terminator
43
+ str
44
+ end
45
+
46
+ def to_hash
47
+ {
48
+ :start => start,
49
+ :finish => finish,
50
+ :starter => starter ? starter.to_hash : nil,
51
+ :terminator => terminator ? terminator.to_hash : nil
52
+ }
53
+ end
54
+ end
55
+
56
+ Positional = Struct.new(:cardinality, :fragment) do
57
+ def to_s
58
+ card_s = case cardinality
59
+ when 1 then "1st"
60
+ when 2 then "2nd"
61
+ when 3 then "3rd"
62
+ end
63
+
64
+ if cardinality
65
+ "#{card_s} #{fragment}"
66
+ else
67
+ fragment
68
+ end
69
+ end
70
+
71
+ def to_hash
72
+ {
73
+ :cardinality => cardinality,
74
+ :fragment => fragment
75
+ }
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Parsers
5
+ module ScienceHealth
6
+
7
+ class CitationNode < Treetop::Runtime::SyntaxNode
8
+ def to_sexp
9
+ [[:page, page.to_sexp], [:lines, line_list.to_sexp]]
10
+ end
11
+
12
+ def to_object
13
+ CSKit::Parsers::ScienceHealth::Citation.new(
14
+ page.text_value,
15
+ line_list.to_object
16
+ )
17
+ end
18
+ end
19
+
20
+ class PageNode < Treetop::Runtime::SyntaxNode
21
+ def to_sexp
22
+ text_value
23
+ end
24
+ end
25
+
26
+ class LineListNode < Treetop::Runtime::SyntaxNode
27
+ def to_sexp
28
+ result = [line.to_sexp]
29
+
30
+ if elements[1] && elements[1].respond_to?(:line_list)
31
+ result += elements[1].line_list.to_sexp
32
+ end
33
+
34
+ result
35
+ end
36
+
37
+ def to_object
38
+ to_sexp.map do |line|
39
+ only = line[1] == :only
40
+ CSKit::Parsers::ScienceHealth::Line.new(
41
+ line[0].first,
42
+ line[0].last,
43
+ only,
44
+ only ? nil : line[1]
45
+ )
46
+ end
47
+ end
48
+ end
49
+
50
+ class LineNode < Treetop::Runtime::SyntaxNode
51
+ def to_sexp
52
+ elements.flat_map { |e| e.to_sexp if e.respond_to?(:to_sexp) }
53
+ end
54
+ end
55
+
56
+ class CompoundLineNumberNode < Treetop::Runtime::SyntaxNode
57
+ def to_sexp
58
+ [[line_number1.text_value.to_i, line_number2.text_value.to_i]]
59
+ end
60
+ end
61
+
62
+ class LineNumberNode < Treetop::Runtime::SyntaxNode
63
+ def to_sexp
64
+ [[text_value.to_i, nil]]
65
+ end
66
+ end
67
+
68
+ class OnlyNode < Treetop::Runtime::SyntaxNode
69
+ def to_sexp
70
+ :only
71
+ end
72
+ end
73
+
74
+ class StartFragmentNode < Treetop::Runtime::SyntaxNode
75
+ def to_sexp
76
+ text_value.strip
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Parsers
5
+ module ScienceHealth
6
+
7
+ Citation = Struct.new(:page, :lines) do
8
+ def to_s
9
+ "#{page}:#{lines.map(&:to_s).join(", ")}"
10
+ end
11
+
12
+ def to_hash
13
+ {
14
+ :page => page,
15
+ :lines => lines.map(&:to_hash)
16
+ }
17
+ end
18
+ end
19
+
20
+ Line = Struct.new(:start, :finish, :only, :start_fragment) do
21
+ alias :only? :only
22
+
23
+ def to_s
24
+ str = if finish
25
+ "#{start}-#{finish}"
26
+ else
27
+ start.to_s
28
+ end
29
+
30
+ str << " (only)" if only?
31
+ str << " #{start_fragment}" if start_fragment
32
+ str
33
+ end
34
+
35
+ def to_hash
36
+ {
37
+ :start => start,
38
+ :finish => finish,
39
+ :only => only,
40
+ :start_fragment => start_fragment
41
+ }
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end