truncate 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/truncate.rb +14 -0
- metadata +3 -2
data/lib/truncate.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
+
##
|
2
|
+
# truncate extends String to shorten text by character length or number of
|
3
|
+
# words.
|
4
|
+
|
1
5
|
class String
|
6
|
+
|
7
|
+
##
|
8
|
+
# The main "truncate" class can be passed a length (in number of characters)
|
9
|
+
# and / or a custom omission.
|
10
|
+
# The default length is 20 characters and the default omission is "...".
|
2
11
|
|
3
12
|
def truncate(length = 20, omis = "...")
|
4
13
|
text = self.dup
|
@@ -8,6 +17,11 @@ class String
|
|
8
17
|
text
|
9
18
|
end
|
10
19
|
|
20
|
+
##
|
21
|
+
# The "words" method can be passed a length (in number of words,
|
22
|
+
# splitting on " ") and / or a custom omission.
|
23
|
+
# The default length is 5 words and the default omission is "...".
|
24
|
+
|
11
25
|
def words(length = 5, omis = "...")
|
12
26
|
text = self.dup
|
13
27
|
array = text.split(" ")
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: truncate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Richard Myers
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-13 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Extends String to truncate by character length or number of words.
|
@@ -53,3 +53,4 @@ specification_version: 3
|
|
53
53
|
summary: Make long strings into slightly less long strings!
|
54
54
|
test_files:
|
55
55
|
- test/test_truncate.rb
|
56
|
+
has_rdoc:
|