summary 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/lib/summary.rb +15 -10
- 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
@@ -36,16 +36,10 @@ module Summary
|
|
36
36
|
# Checks the need of "summarize" the string. When it is needed, the string is splitted.
|
37
37
|
# Then the last dot is removed and the terminator is pushed into the resultant string.
|
38
38
|
def summary
|
39
|
-
return pure
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if limit >= purify(@terminator).size
|
44
|
-
text = pure[0...limit]
|
45
|
-
text = text.gsub(/\.$/,'') + @terminator
|
46
|
-
else
|
47
|
-
pure
|
48
|
-
end
|
39
|
+
return pure unless summarizable?
|
40
|
+
|
41
|
+
text = pure[0...string_limit]
|
42
|
+
text = text.gsub(/\.$/,'') + @terminator
|
49
43
|
end
|
50
44
|
|
51
45
|
protected
|
@@ -54,9 +48,20 @@ module Summary
|
|
54
48
|
@pure ||= purify @text
|
55
49
|
end
|
56
50
|
|
51
|
+
# Cleans up any string removing the html tags, break lines and white spaces.
|
57
52
|
def purify(string)
|
58
53
|
string.strip.gsub(/<(.|\n)+?>|(\t|\n|\r)+/,'').gsub(/\s+/,' ')
|
59
54
|
end
|
55
|
+
|
56
|
+
# Calculates the size limit to summarize the string.
|
57
|
+
def string_limit
|
58
|
+
@string_limit ||= pure[0..(@size-backspace)].rindex(' ')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Verifies if the string can be summarized.
|
62
|
+
def summarizable?
|
63
|
+
pure.size > @size and pure =~ /\s/ and string_limit >= purify(@terminator).size
|
64
|
+
end
|
60
65
|
|
61
66
|
# Measures the space needed by the terminator.
|
62
67
|
# Let's say you want a string with 50 chars, and your terminator is a '...'.
|
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: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 5
|
10
|
+
version: 0.6.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bruno Azisaka Maciel
|
metadata.gz.sig
CHANGED
Binary file
|