wordtree 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/lib/wordtree/archdown.rb +58 -0
- data/lib/wordtree/book.rb +38 -0
- data/lib/wordtree/librarian.rb +58 -0
- data/lib/wordtree/library.rb +41 -0
- data/lib/wordtree/library_locator.rb +44 -0
- data/lib/wordtree/text_utils.rb +73 -0
- data/lib/wordtree/version.rb +3 -0
- data/lib/wordtree.rb +5 -0
- data/spec/fixtures/cassettes/archive_org_download_book.yml +1627 -0
- data/spec/fixtures/library/bo/ok/book/book.md +4 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/wordtree/book_spec.rb +19 -0
- data/spec/wordtree/librarian_spec.rb +48 -0
- data/spec/wordtree/library_spec.rb +23 -0
- data/spec/wordtree/text_utils_spec.rb +54 -0
- data/wordtree.gemspec +34 -0
- metadata +269 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'vcr'
|
8
|
+
|
9
|
+
module Fixtures
|
10
|
+
def fixture(name)
|
11
|
+
File.join(File.dirname(__FILE__), 'fixtures', name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
VCR.configure do |c|
|
16
|
+
include Fixtures
|
17
|
+
c.cassette_library_dir = fixture('cassettes')
|
18
|
+
c.hook_into :webmock
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
config.filter_run :focus
|
24
|
+
|
25
|
+
config.include Fixtures
|
26
|
+
|
27
|
+
# Run specs in random order to surface order dependencies. If you find an
|
28
|
+
# order dependency and want to debug it, you can fix the order by providing
|
29
|
+
# the seed, which is printed after each run.
|
30
|
+
# --seed 1234
|
31
|
+
config.order = 'random'
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordtree/book'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe WordTree::Book do
|
6
|
+
it "initializes" do
|
7
|
+
expect{ WordTree::Book.new }.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "file_id defaults to archive_org_id" do
|
11
|
+
book = WordTree::Book.new(:archive_org_id => "abc")
|
12
|
+
expect(book.id).to eq("abc")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can return cleaned content" do
|
16
|
+
book = WordTree::Book.create("book", {}, "Wi&ld\nContent!")
|
17
|
+
expect(book.clean_content).to eq("wild content\n")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'preamble'
|
4
|
+
require 'wordtree/librarian'
|
5
|
+
|
6
|
+
describe WordTree::Librarian do
|
7
|
+
let(:root) { Dir.mktmpdir }
|
8
|
+
let(:library) { WordTree::Library.new(root) }
|
9
|
+
let(:librarian) { WordTree::Librarian.new(library) }
|
10
|
+
|
11
|
+
it "downloads an archive.org book" do
|
12
|
+
VCR.use_cassette('archive_org_download_book') do
|
13
|
+
librarian.archive_org_get_book("firstbooknapole00gruagoog")
|
14
|
+
book = librarian.find("firstbooknapole00gruagoog")
|
15
|
+
expect(book.year).to eq(1809)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with fixture library" do
|
20
|
+
# Need a read-only library with fixtures in it for some tests
|
21
|
+
let(:root) { fixture("library") }
|
22
|
+
|
23
|
+
it "loads book from disk" do
|
24
|
+
book = librarian.find("book")
|
25
|
+
expect(book.id).to eq("book")
|
26
|
+
expect(book.year).to eq(1800)
|
27
|
+
expect(book.content).to eq("Book with content")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "saves to disk (yaml, content)" do
|
31
|
+
tmp_root = Dir.mktmpdir
|
32
|
+
tmp_library = WordTree::Library.new(tmp_root)
|
33
|
+
tmp_librarian = WordTree::Librarian.new(tmp_library)
|
34
|
+
|
35
|
+
book = librarian.find("book")
|
36
|
+
|
37
|
+
book.source = "test"
|
38
|
+
book.content += "."
|
39
|
+
|
40
|
+
tmp_librarian.save(book)
|
41
|
+
|
42
|
+
updated = Preamble.load(tmp_library.path_to("book"))
|
43
|
+
expect(updated.metadata).to eq({:year => 1800, :source => "test"})
|
44
|
+
expect(updated.content).to eq("Book with content.")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordtree/library'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
describe WordTree::Library do
|
6
|
+
let(:root) { Dir.mktmpdir('library') }
|
7
|
+
let(:library) { WordTree::Library.new(root) }
|
8
|
+
|
9
|
+
it "initializes with path" do
|
10
|
+
expect(library.root).to eq(root)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "gets dir_of a book_id" do
|
14
|
+
expect(library.dir_of("abcd")).to eq(File.join(root, "/ab/cd/abcd"))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "mkdir makes a directory on disk" do
|
18
|
+
book_id = 'xyz'
|
19
|
+
expect(File.exist?(library.dir_of(book_id))).to be_falsy
|
20
|
+
library.mkdir(book_id)
|
21
|
+
expect(File.exist?(library.dir_of(book_id))).to be_truthy
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordtree/text_utils'
|
3
|
+
|
4
|
+
describe WordTree::TextUtils do
|
5
|
+
context "#split_near" do
|
6
|
+
it "splits on spaces" do
|
7
|
+
line, rem = WordTree::TextUtils.split_near("it is near", 7)
|
8
|
+
expect(line).to eq("it is")
|
9
|
+
expect(rem).to eq("near")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "removes a space if index lands on one" do
|
13
|
+
line, rem = WordTree::TextUtils.split_near("it is near", 5)
|
14
|
+
expect(line).to eq("it is")
|
15
|
+
expect(rem).to eq("near")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "keeps the whole line if index is >= length of line" do
|
19
|
+
line, rem = WordTree::TextUtils.split_near("it is near", 10)
|
20
|
+
expect(line).to eq("it is near")
|
21
|
+
expect(rem).to eq("")
|
22
|
+
|
23
|
+
line, rem = WordTree::TextUtils.split_near("it is near", 11)
|
24
|
+
expect(line).to eq("it is near")
|
25
|
+
expect(rem).to eq("")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "splits at the index anyway if no spaces are found" do
|
29
|
+
line, rem = WordTree::TextUtils.split_near("itisnear", 4)
|
30
|
+
expect(line).to eq("itis")
|
31
|
+
expect(rem).to eq("near")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "#clean_text" do
|
36
|
+
let(:sample_text) { "This, [here] is awesome, right?" }
|
37
|
+
it "wraps" do
|
38
|
+
cleaned = WordTree::TextUtils.clean_text(sample_text, 10)
|
39
|
+
expect(cleaned).to eq("this here\nis awesome\nright\n")
|
40
|
+
|
41
|
+
cleaned = WordTree::TextUtils.clean_text(sample_text, 15)
|
42
|
+
expect(cleaned).to eq("this here is\nawesome right\n")
|
43
|
+
|
44
|
+
cleaned = WordTree::TextUtils.clean_text(sample_text, 150)
|
45
|
+
expect(cleaned).to eq("this here is awesome right\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:sample_dash) { "What-\never\ndo you\n mean?"}
|
49
|
+
it "joins lines ending in -" do
|
50
|
+
cleaned = WordTree::TextUtils.clean_text(sample_dash, 10)
|
51
|
+
expect(cleaned).to eq("whatever\ndo you\nmean\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/wordtree.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wordtree/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wordtree"
|
8
|
+
spec.version = Wordtree::VERSION
|
9
|
+
spec.authors = ["Duane Johnson"]
|
10
|
+
spec.email = ["duane.johnson@gmail.com"]
|
11
|
+
spec.description = %q{WordTree common library code}
|
12
|
+
spec.summary = %q{Wordtree common library code}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "virtus"
|
22
|
+
spec.add_dependency "preamble", ">= 0.0.3"
|
23
|
+
spec.add_dependency "archivist-client", ">= 0.1.7"
|
24
|
+
spec.add_dependency "retriable"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "debugger"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "guard"
|
31
|
+
spec.add_development_dependency "guard-rspec"
|
32
|
+
spec.add_development_dependency "vcr"
|
33
|
+
spec.add_development_dependency "webmock"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordtree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Duane Johnson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: virtus
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: preamble
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: archivist-client
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.7
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: retriable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: debugger
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: guard
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: guard-rspec
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: vcr
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: webmock
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
description: WordTree common library code
|
207
|
+
email:
|
208
|
+
- duane.johnson@gmail.com
|
209
|
+
executables: []
|
210
|
+
extensions: []
|
211
|
+
extra_rdoc_files: []
|
212
|
+
files:
|
213
|
+
- .gitignore
|
214
|
+
- .rspec
|
215
|
+
- Gemfile
|
216
|
+
- Guardfile
|
217
|
+
- LICENSE.txt
|
218
|
+
- README.md
|
219
|
+
- Rakefile
|
220
|
+
- lib/wordtree.rb
|
221
|
+
- lib/wordtree/archdown.rb
|
222
|
+
- lib/wordtree/book.rb
|
223
|
+
- lib/wordtree/librarian.rb
|
224
|
+
- lib/wordtree/library.rb
|
225
|
+
- lib/wordtree/library_locator.rb
|
226
|
+
- lib/wordtree/text_utils.rb
|
227
|
+
- lib/wordtree/version.rb
|
228
|
+
- spec/fixtures/cassettes/archive_org_download_book.yml
|
229
|
+
- spec/fixtures/library/bo/ok/book/book.md
|
230
|
+
- spec/spec_helper.rb
|
231
|
+
- spec/wordtree/book_spec.rb
|
232
|
+
- spec/wordtree/librarian_spec.rb
|
233
|
+
- spec/wordtree/library_spec.rb
|
234
|
+
- spec/wordtree/text_utils_spec.rb
|
235
|
+
- wordtree.gemspec
|
236
|
+
homepage: ''
|
237
|
+
licenses:
|
238
|
+
- MIT
|
239
|
+
post_install_message:
|
240
|
+
rdoc_options: []
|
241
|
+
require_paths:
|
242
|
+
- lib
|
243
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
244
|
+
none: false
|
245
|
+
requirements:
|
246
|
+
- - ! '>='
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '0'
|
249
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
|
+
none: false
|
251
|
+
requirements:
|
252
|
+
- - ! '>='
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: '0'
|
255
|
+
requirements: []
|
256
|
+
rubyforge_project:
|
257
|
+
rubygems_version: 1.8.23
|
258
|
+
signing_key:
|
259
|
+
specification_version: 3
|
260
|
+
summary: Wordtree common library code
|
261
|
+
test_files:
|
262
|
+
- spec/fixtures/cassettes/archive_org_download_book.yml
|
263
|
+
- spec/fixtures/library/bo/ok/book/book.md
|
264
|
+
- spec/spec_helper.rb
|
265
|
+
- spec/wordtree/book_spec.rb
|
266
|
+
- spec/wordtree/librarian_spec.rb
|
267
|
+
- spec/wordtree/library_spec.rb
|
268
|
+
- spec/wordtree/text_utils_spec.rb
|
269
|
+
has_rdoc:
|