summary 0.6.3 → 0.6.4
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/CHANGELOG +2 -0
- data/lib/summary.rb +14 -4
- data/spec/summary_spec.rb +11 -1
- data/summary.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data/CHANGELOG
CHANGED
data/lib/summary.rb
CHANGED
@@ -38,21 +38,31 @@ module Summary
|
|
38
38
|
def summary
|
39
39
|
return pure if pure.size < @size or pure !~ /\s/
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
limit = pure[0..(@size-backspace)].rindex(' ')
|
42
|
+
|
43
|
+
if limit >= purify(@terminator).size
|
44
|
+
text = pure[0...limit]
|
45
|
+
text = text.gsub(/\.$/,'') + @terminator
|
46
|
+
else
|
47
|
+
pure
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
protected
|
46
52
|
# It cleans up the text removing the html tags, break lines and white spaces
|
47
53
|
def pure
|
48
|
-
@pure ||= @text
|
54
|
+
@pure ||= purify @text
|
55
|
+
end
|
56
|
+
|
57
|
+
def purify(string)
|
58
|
+
string.strip.gsub(/<(.|\n)+?>|(\t|\n|\r)+/,'').gsub(/\s+/,' ')
|
49
59
|
end
|
50
60
|
|
51
61
|
# Measures the space needed by the terminator.
|
52
62
|
# Let's say you want a string with 50 chars, and your terminator is a '...'.
|
53
63
|
# That means your string can only have 47 chars + 3 chars from your terminator.
|
54
64
|
def backspace
|
55
|
-
(@terminator =~ /<(.|\n)+?>/ ? @terminator
|
65
|
+
(@terminator =~ /<(.|\n)+?>/ ? purify(@terminator) : @terminator).size
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
data/spec/summary_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe Summary, 'on plain text' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe Summary, "when the string is
|
37
|
+
describe Summary, "when the string is a word" do
|
38
38
|
before do
|
39
39
|
@text = "test"
|
40
40
|
end
|
@@ -46,6 +46,16 @@ describe Summary, "when the string is thin" do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe Summary, "when the terminator is bigger" do
|
50
|
+
before do
|
51
|
+
@text = "test test"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not summarize the string" do
|
55
|
+
@text.summary(4, '.' * 5).should == @text
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
describe Summary, 'on html' do
|
50
60
|
before do
|
51
61
|
@text = 'Cras <strong>eleifend sodales sem</strong>. <img src="image.jpg" /><h1>Ut</h1> nec metus. <br />Nulla sed<p> nisl. Praesent malesuada</p> dui rhoncus quam. Aliquam ultricies. Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis, mi metus sagittis augue, <strong>sed</strong> hendrerit nunc felis eget neque. Fusce vel massa. Quisque ligula enim, tempor sed, lacinia non, malesuada ac, enim. Curabitur at enim scelerisque neque egestas luctus. Mauris lacinia varius diam.'
|
data/summary.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: summary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bruno Azisaka Maciel
|
metadata.gz.sig
CHANGED
Binary file
|