summary 0.6.6 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +19 -0
- data/Manifest +4 -2
- data/Rakefile +2 -1
- data/lib/summary.rb +5 -5
- data/spec/{summary_spec.rb → lib/summary_spec.rb} +48 -48
- data/spec/spec_helper.rb +5 -24
- data/summary.gemspec +3 -3
- metadata +9 -7
data/CHANGELOG
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/Manifest
CHANGED
data/Rakefile
CHANGED
data/lib/summary.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Summary
|
2
2
|
MAJOR = '0'
|
3
|
-
TINY = '
|
4
|
-
PATCH = '
|
3
|
+
TINY = '7'
|
4
|
+
PATCH = '2'
|
5
5
|
VERSION = [MAJOR, TINY, PATCH] * '.'
|
6
6
|
|
7
7
|
module String
|
@@ -36,7 +36,7 @@ module Summary
|
|
36
36
|
def summary
|
37
37
|
return pure unless summarizable?
|
38
38
|
|
39
|
-
pure[0...string_limit].
|
39
|
+
pure[0...string_limit].sub(/\.$/,'') + @terminator
|
40
40
|
end
|
41
41
|
|
42
42
|
protected
|
@@ -47,7 +47,7 @@ module Summary
|
|
47
47
|
|
48
48
|
# Cleans up any string removing the html tags, break lines and white spaces.
|
49
49
|
def purify(string)
|
50
|
-
string.gsub(/(^\s+)|<(.|\n)+?>|(\t|\n|\r)+/,'').
|
50
|
+
string.gsub(/(^\s+)|<(.|\n)+?>|(\t|\n|\r)+/,'').sub(/\s+/,' ')
|
51
51
|
end
|
52
52
|
|
53
53
|
# Calculates the size limit to summarize the string.
|
@@ -69,4 +69,4 @@ module Summary
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
String.send(:include, Summary::String)
|
72
|
+
String.send(:include, Summary::String)
|
@@ -1,96 +1,96 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
|
-
describe Summary
|
3
|
+
describe 'Summary on plain text' do
|
4
4
|
before do
|
5
5
|
@text = 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam. Aliquam ultricies. Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis, mi metus sagittis augue, sed 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.'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
describe "by default" do
|
9
9
|
before do
|
10
10
|
@summarized = @text.summary
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should break the text' do
|
14
|
-
|
14
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...', @summarized
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should have 100 chars" do
|
18
|
-
@summarized
|
18
|
+
assert_summary_to @summarized, 100
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
describe "limited to 50 chars" do
|
23
23
|
before do
|
24
24
|
@summarized = @text.summary(50)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should break the text" do
|
28
|
-
|
28
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla...', @summarized
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should have 50 chars" do
|
32
|
-
@summarized
|
32
|
+
assert_summary_to @summarized, 50
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe Summary
|
37
|
+
describe "Summary when the string is a word" do
|
38
38
|
before do
|
39
39
|
@text = "test"
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
describe "when the summary size is lower than the string size" do
|
43
43
|
it "should not summarize the string" do
|
44
|
-
@text.summary(2)
|
44
|
+
assert_equal @text, @text.summary(2)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
describe Summary
|
49
|
+
describe 'Summary when the terminator is bigger' do
|
50
50
|
before do
|
51
51
|
@text = "test test"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not summarize the string" do
|
55
|
-
@text.summary(4, '.' * 5)
|
55
|
+
assert_equal @text, @text.summary(4, '.' * 5)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe Summary
|
59
|
+
describe 'Summary on html' do
|
60
60
|
before do
|
61
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.'
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
describe "by default" do
|
65
65
|
before do
|
66
66
|
@summarized = @text.summary
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should break the text" do
|
70
|
-
|
70
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...', @summarized
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should have 100 chars" do
|
74
|
-
@summarized
|
74
|
+
assert_summary_to @summarized, 100
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
describe "limited to 50 chars" do
|
79
79
|
before do
|
80
80
|
@summarized = @text.summary(50)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should break the text" do
|
84
|
-
|
84
|
+
assert 'Cras eleifend sodales sem. Ut nec metus. Nulla...', @summarized
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'should have 50 chars' do
|
88
|
-
@summarized
|
88
|
+
assert_summary_to @summarized, 50
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe Summary
|
93
|
+
describe 'Summary on complex text' do
|
94
94
|
before do
|
95
95
|
@text = <<-BREAK
|
96
96
|
Cras <strong>eleifend sodales sem</strong>.
|
@@ -102,129 +102,129 @@ describe Summary, 'on complex text' do
|
|
102
102
|
BREAK
|
103
103
|
end
|
104
104
|
|
105
|
-
|
105
|
+
describe "by default" do
|
106
106
|
before do
|
107
107
|
@summarized = @text.summary
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should break the text" do
|
111
|
-
|
111
|
+
assert 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...', @summarized
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should have 100 chars' do
|
115
|
-
@summarized
|
115
|
+
assert_summary_to @summarized, 100
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
|
119
|
+
describe "limited to 50 chars" do
|
120
120
|
before do
|
121
121
|
@summarized = @text.summary(50)
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should break the text" do
|
125
|
-
|
125
|
+
assert 'Cras eleifend sodales sem. Ut nec metus. Nulla...', @summarized
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'should have 50 chars' do
|
129
|
-
@summarized
|
129
|
+
assert_summary_to @summarized, 50
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe Summary
|
134
|
+
describe 'Summary on tiny text' do
|
135
135
|
before do
|
136
136
|
@text = 'Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis.'
|
137
137
|
end
|
138
138
|
|
139
|
-
|
139
|
+
describe "by default" do
|
140
140
|
before do
|
141
141
|
@summarized = @text.summary
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should not break the text" do
|
145
|
-
|
145
|
+
assert_equal 'Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis.', @summarized
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should have 100 chars" do
|
149
|
-
@summarized
|
149
|
+
assert_summary_to @summarized, 100
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
-
|
153
|
+
describe "limited to 50 chars" do
|
154
154
|
before do
|
155
155
|
@summarized = @text.summary(50)
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should break the text" do
|
159
|
-
|
159
|
+
assert_equal 'Praesent commodo. Nam nec pede. Pellentesque...', @summarized
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should have 50 chars" do
|
163
|
-
@summarized
|
163
|
+
assert_summary_to @summarized, 50
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
|
169
|
-
describe Summary
|
169
|
+
describe 'Summary with different terminators' do
|
170
170
|
before do
|
171
171
|
@text = 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam. Aliquam ultricies. Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis, mi metus sagittis augue, sed 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.'
|
172
172
|
end
|
173
173
|
|
174
|
-
|
175
|
-
|
174
|
+
describe "limited to 50 chars" do
|
175
|
+
describe "with !" do
|
176
176
|
before do
|
177
177
|
@summarized = @text.summary(50, '!')
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should end with !" do
|
181
|
-
|
181
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla!', @summarized
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should have 50 chars" do
|
185
|
-
@summarized
|
185
|
+
assert_summary_to @summarized, 50
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
|
189
|
+
describe "with ." do
|
190
190
|
before do
|
191
191
|
@summarized = @text.summary(50, '.')
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should end with ." do
|
195
|
-
|
195
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla.', @summarized
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should have 50 chars" do
|
199
|
-
@summarized
|
199
|
+
assert_summary_to @summarized, 50
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
|
203
|
+
describe "with nothing" do
|
204
204
|
before do
|
205
205
|
@summarized = @text.summary(50, '')
|
206
206
|
end
|
207
207
|
|
208
208
|
it 'should end with nothing' do
|
209
|
-
|
209
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec metus. Nulla sed', @summarized
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should have 50 chars" do
|
213
|
-
@summarized
|
213
|
+
assert_summary_to @summarized, 50
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
-
|
217
|
+
describe "with html" do
|
218
218
|
before do
|
219
219
|
@summarized = @text.summary(50, '... <a href="#read-more">read more</a>')
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should end with ...<a href=\"#read-more\">read more</a>" do
|
223
|
-
|
223
|
+
assert_equal 'Cras eleifend sodales sem. Ut nec... <a href="#read-more">read more</a>', @summarized
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should have 50 chars" do
|
227
|
-
@summarized
|
227
|
+
assert_summary_to @summarized, 50
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,29 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require
|
2
|
+
require 'minitest/spec'
|
3
3
|
|
4
|
-
|
5
|
-
module Matchers
|
6
|
-
class SummarizableOf
|
7
|
-
def initialize(size)
|
8
|
-
@size = size
|
9
|
-
end
|
10
|
-
|
11
|
-
def matches?(actual)
|
12
|
-
@actual = actual
|
13
|
-
actual.gsub(/<(.|\n)+?>/,'').size.should <= @size
|
14
|
-
end
|
15
|
-
end
|
4
|
+
MiniTest::Unit.autorun
|
16
5
|
|
17
|
-
|
18
|
-
SummarizableOf.new(size)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
6
|
+
require File.dirname(__FILE__) + '/../lib/summary'
|
22
7
|
|
23
|
-
|
24
|
-
|
25
|
-
Spec::Runner.configure { |config| config.include(Summary::Matchers) }
|
26
|
-
rescue LoadError
|
27
|
-
require 'rspec'
|
28
|
-
RSpec.configure { |config| config.include(Summary::Matchers) }
|
8
|
+
def assert_summary_to(string, size)
|
9
|
+
assert string.gsub(/<(.|\n)+?>/,'').size <= size
|
29
10
|
end
|
data/summary.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{summary}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.7.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Bruno Azisaka Maciel"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-10-26}
|
10
10
|
s.description = %q{This is a simple gem that generates introduction text from a long text, it will always break the text at the end of the last word near to the limit you informed as argument.}
|
11
11
|
s.email = %q{bruno [at] bubble [dot] com [dot] br}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/summary.rb"]
|
13
|
-
s.files = ["CHANGELOG", "
|
13
|
+
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "README.rdoc", "Rakefile", "lib/summary.rb", "rails/init.rb", "spec/lib/summary_spec.rb", "spec/spec_helper.rb", "summary.gemspec", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/azisaka/summary}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Summary", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
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: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bruno Azisaka Maciel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-26 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -31,14 +31,16 @@ extra_rdoc_files:
|
|
31
31
|
- lib/summary.rb
|
32
32
|
files:
|
33
33
|
- CHANGELOG
|
34
|
-
-
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
35
36
|
- README.rdoc
|
36
37
|
- Rakefile
|
37
38
|
- lib/summary.rb
|
38
39
|
- rails/init.rb
|
40
|
+
- spec/lib/summary_spec.rb
|
39
41
|
- spec/spec_helper.rb
|
40
|
-
- spec/summary_spec.rb
|
41
42
|
- summary.gemspec
|
43
|
+
- Manifest
|
42
44
|
has_rdoc: true
|
43
45
|
homepage: http://github.com/azisaka/summary
|
44
46
|
licenses: []
|