bookie 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bookie/parser.rb +12 -2
- data/lib/bookie/version.rb +1 -1
- data/test/fixtures/single_paragraph.md +7 -0
- data/test/suite.rb +1 -0
- data/test/units/document_test.rb +2 -2
- data/test/units/parser_test.rb +19 -0
- metadata +4 -2
data/lib/bookie/parser.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
module Bookie
|
2
|
+
ContentTree = Struct.new(:children)
|
3
|
+
Paragraph = Struct.new(:children)
|
4
|
+
|
2
5
|
class Parser
|
3
6
|
def self.parse(contents)
|
4
7
|
parser = new(contents)
|
5
8
|
parser.document_tree
|
6
9
|
end
|
7
10
|
|
11
|
+
attr_reader :document_tree
|
12
|
+
|
8
13
|
def initialize(contents)
|
9
14
|
generate_document_tree(contents)
|
10
15
|
end
|
11
16
|
|
12
|
-
|
17
|
+
def extract_paragraphs(contents)
|
18
|
+
contents.split(/\n\n+/).each do |e|
|
19
|
+
document_tree.children << Paragraph.new([e])
|
20
|
+
end
|
21
|
+
end
|
13
22
|
|
14
23
|
private
|
15
24
|
|
16
25
|
def generate_document_tree(contents)
|
17
|
-
@document_tree =
|
26
|
+
@document_tree = ContentTree.new([])
|
27
|
+
extract_paragraphs(contents)
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
data/lib/bookie/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
However, it isn’t sufficient just to have a group of people studying the craft
|
2
|
+
of software development: those have existed as long as software has existed and
|
3
|
+
if they were capable of closing this gap, they would have done so by now. A lack
|
4
|
+
of sufficient context is what most frequently leads to tribalism in software
|
5
|
+
communities, and the end result is a polarizing effect that causes direct harm
|
6
|
+
to real progress by generating far more heat than light whenever a certain tool
|
7
|
+
or technique is discussed.
|
data/test/suite.rb
CHANGED
data/test/units/document_test.rb
CHANGED
@@ -2,9 +2,9 @@ require_relative "../test_helper"
|
|
2
2
|
|
3
3
|
context "A Document" do
|
4
4
|
test "should be parsed into an array of contents" do
|
5
|
-
sample_text = fixture("multi_paragraph_document.
|
5
|
+
sample_text = fixture("multi_paragraph_document.md")
|
6
6
|
document = Bookie::Document.new(sample_text)
|
7
7
|
|
8
|
-
refute document.contents.empty?, "contents should not be empty"
|
8
|
+
refute document.contents.children.empty?, "contents should not be empty"
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
context "A Parser" do
|
4
|
+
test "should know about paragraphs" do
|
5
|
+
sample_text = File.read(fixture("multi_paragraph_document.md"))
|
6
|
+
|
7
|
+
# NOTE: Is this the behavior we'd expect?
|
8
|
+
sample_paragraph_text = File.read(fixture("single_paragraph.md")).chomp
|
9
|
+
|
10
|
+
tree = Bookie::Parser.parse(sample_text)
|
11
|
+
|
12
|
+
assert_equal 8, tree.children.length
|
13
|
+
|
14
|
+
actual_paragraph = tree.children[4]
|
15
|
+
actual_paragraph_text = actual_paragraph.children.first
|
16
|
+
|
17
|
+
assert_equal sample_paragraph_text, actual_paragraph_text
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gregory Brown
|
@@ -14,7 +14,7 @@ date: 2011-04-23 00:00:00 -04:00
|
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
17
|
-
description: Eventually this may be a markdown to PDF, ePUB,
|
17
|
+
description: Eventually this may be a markdown to PDF, ePUB, MOBI processor. For now it's just something I'm playing around with, so use at your own risk
|
18
18
|
email:
|
19
19
|
- gregory.t.brown@gmail.com
|
20
20
|
executables: []
|
@@ -29,9 +29,11 @@ files:
|
|
29
29
|
- lib/bookie/version.rb
|
30
30
|
- lib/bookie.rb
|
31
31
|
- test/fixtures/multi_paragraph_document.md
|
32
|
+
- test/fixtures/single_paragraph.md
|
32
33
|
- test/suite.rb
|
33
34
|
- test/test_helper.rb
|
34
35
|
- test/units/document_test.rb
|
36
|
+
- test/units/parser_test.rb
|
35
37
|
- GPLv3
|
36
38
|
- README.md
|
37
39
|
- CHANGELOG.md
|