wordtree 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,8 @@ module WordTree
|
|
16
16
|
# The book ID to locate
|
17
17
|
attr_reader :id
|
18
18
|
|
19
|
+
NotPath = Class.new(StandardError)
|
20
|
+
|
19
21
|
# Construct a LibraryLocator from a string (book ID)
|
20
22
|
def initialize(id)
|
21
23
|
@id = id
|
@@ -41,6 +43,11 @@ module WordTree
|
|
41
43
|
def self.identity(id)
|
42
44
|
id.is_a?(LibraryLocator) ? id : new(id)
|
43
45
|
end
|
46
|
+
|
47
|
+
def self.id_from_path(path)
|
48
|
+
raise NotPath, "not a path" if path.nil? or !path.is_a?(String)
|
49
|
+
File.basename(path).sub(/\.[^\.]+$/, '')
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/wordtree/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wordtree/disk/library'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
describe WordTree::Disk::LibraryLocator do
|
6
|
+
describe "#id_from_path" do
|
7
|
+
it "disallows non-strings" do
|
8
|
+
expect{ WordTree::Disk::LibraryLocator.id_from_path(:test) }.to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "removes the directory" do
|
12
|
+
id = WordTree::Disk::LibraryLocator.id_from_path("/path/to/book.txt")
|
13
|
+
expect(id).to eq "book"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "removes the suffix" do
|
17
|
+
id = WordTree::Disk::LibraryLocator.id_from_path("/path/to/book.txt.md")
|
18
|
+
expect(id).to eq "book.txt"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -265,6 +265,7 @@ files:
|
|
265
265
|
- spec/wordtree/book_spec.rb
|
266
266
|
- spec/wordtree/db/librarian_spec.rb
|
267
267
|
- spec/wordtree/disk/librarian_spec.rb
|
268
|
+
- spec/wordtree/disk/library_locator_spec.rb
|
268
269
|
- spec/wordtree/disk/library_spec.rb
|
269
270
|
- spec/wordtree/text_utils_spec.rb
|
270
271
|
- wordtree.gemspec
|
@@ -301,6 +302,7 @@ test_files:
|
|
301
302
|
- spec/wordtree/book_spec.rb
|
302
303
|
- spec/wordtree/db/librarian_spec.rb
|
303
304
|
- spec/wordtree/disk/librarian_spec.rb
|
305
|
+
- spec/wordtree/disk/library_locator_spec.rb
|
304
306
|
- spec/wordtree/disk/library_spec.rb
|
305
307
|
- spec/wordtree/text_utils_spec.rb
|
306
308
|
has_rdoc:
|