sep 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sep/separator.rb +9 -5
- data/lib/sep/version.rb +1 -1
- data/spec/separator_spec.rb +11 -5
- metadata +1 -1
data/lib/sep/separator.rb
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
module Sep
|
2
2
|
class Separator
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :text, :words_data
|
4
4
|
|
5
5
|
ANALYSIS = /([[:punct:]\s]*)(\w+)([[:punct:]]*)(\s*)/
|
6
6
|
|
7
7
|
# text - String text to separate
|
8
8
|
def initialize(text)
|
9
|
-
@
|
9
|
+
@text = text
|
10
10
|
|
11
11
|
analyze
|
12
12
|
end
|
13
13
|
|
14
14
|
def leading_space
|
15
|
-
|
15
|
+
text.match(/(\s*)/).captures[0]
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def space
|
19
19
|
[leading_space] + words_data.map {|wd| wd[:space_post] }
|
20
20
|
end
|
21
21
|
|
22
|
+
def words
|
23
|
+
words_data.map {|wd| wd[:word] }
|
24
|
+
end
|
25
|
+
|
22
26
|
private
|
23
27
|
|
24
28
|
def scanned_text
|
25
|
-
|
29
|
+
text.scan(ANALYSIS)
|
26
30
|
end
|
27
31
|
|
28
32
|
def analyze
|
data/lib/sep/version.rb
CHANGED
data/spec/separator_spec.rb
CHANGED
@@ -5,10 +5,11 @@ describe Sep::Separator do
|
|
5
5
|
|
6
6
|
let(:sep) { described_class.new(text) }
|
7
7
|
|
8
|
-
describe "#
|
9
|
-
subject { sep.
|
8
|
+
describe "#text" do
|
9
|
+
subject { sep.text }
|
10
10
|
|
11
11
|
it { should be_a(String) }
|
12
|
+
it { should == text }
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "#words_data" do
|
@@ -37,6 +38,11 @@ describe Sep::Separator do
|
|
37
38
|
end
|
38
39
|
|
39
40
|
describe "#words" do
|
41
|
+
let(:words) { described_class.new(text).words }
|
42
|
+
|
43
|
+
subject { words.slice(0..4) }
|
44
|
+
|
45
|
+
it { should == %w{THE MEANING OF ALCHEMY The} }
|
40
46
|
end
|
41
47
|
|
42
48
|
describe "#leading_space" do
|
@@ -45,11 +51,11 @@ describe Sep::Separator do
|
|
45
51
|
it { should == "\n\n" }
|
46
52
|
end
|
47
53
|
|
48
|
-
describe "#
|
49
|
-
let(:
|
54
|
+
describe "#space" do
|
55
|
+
let(:space) { described_class.new(text).space }
|
50
56
|
|
51
57
|
describe "0..4" do
|
52
|
-
subject {
|
58
|
+
subject { space.slice(0..4) }
|
53
59
|
|
54
60
|
it { should match_array(["\n\n", " ", " ", " ", "\n\n\n"]) }
|
55
61
|
end
|