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 CHANGED
@@ -1,3 +1,5 @@
1
+ v0.7.2. Migrated to Minitest and Bundler
2
+
1
3
  v0.6.6. Refactoring
2
4
 
3
5
  v0.6.5. Code improvements and docs
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :gemcutter
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ summary (0.7.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ minitest (1.7.2)
10
+ rake (0.8.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (>= 1.0.0)
17
+ minitest
18
+ rake
19
+ summary!
data/Manifest CHANGED
@@ -1,9 +1,11 @@
1
1
  CHANGELOG
2
- Manifest
2
+ Gemfile
3
+ Gemfile.lock
3
4
  README.rdoc
4
5
  Rakefile
5
6
  lib/summary.rb
6
7
  rails/init.rb
8
+ spec/lib/summary_spec.rb
7
9
  spec/spec_helper.rb
8
- spec/summary_spec.rb
9
10
  summary.gemspec
11
+ Manifest
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'echoe'
2
- Echoe.new('summary') do |p|
2
+
3
+ Echoe.new('summary') do |p|
3
4
  p.project = 'summary'
4
5
  p.author = 'Bruno Azisaka Maciel'
5
6
  p.email = 'bruno [at] bubble [dot] com [dot] br'
data/lib/summary.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Summary
2
2
  MAJOR = '0'
3
- TINY = '6'
4
- PATCH = '6'
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].gsub(/\.$/,'') + @terminator
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)+/,'').gsub(/\s+/,' ')
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('spec_helper', File.dirname(__FILE__))
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
- describe Summary, 'on plain text' do
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
- context "by default" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...'
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.should be_summarizable_of(100)
18
+ assert_summary_to @summarized, 100
19
19
  end
20
20
  end
21
21
 
22
- context "limited to 50 chars" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla...'
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.should be_summarizable_of(50)
32
+ assert_summary_to @summarized, 50
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
- describe Summary, "when the string is a word" do
37
+ describe "Summary when the string is a word" do
38
38
  before do
39
39
  @text = "test"
40
40
  end
41
41
 
42
- context "when the summary size is lower than the string size" do
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).should == @text
44
+ assert_equal @text, @text.summary(2)
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
- describe Summary, "when the terminator is bigger" do
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).should == @text
55
+ assert_equal @text, @text.summary(4, '.' * 5)
56
56
  end
57
57
  end
58
58
 
59
- describe Summary, 'on html' do
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
- context "by default" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...'
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.should be_summarizable_of(100)
74
+ assert_summary_to @summarized, 100
75
75
  end
76
76
  end
77
77
 
78
- context "limited to 50 chars" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla...'
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.should be_summarizable_of(50)
88
+ assert_summary_to @summarized, 50
89
89
  end
90
90
  end
91
91
  end
92
92
 
93
- describe Summary, 'on complex text' do
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
- context "by default" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla sed nisl. Praesent malesuada dui rhoncus quam...'
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.should be_summarizable_of(100)
115
+ assert_summary_to @summarized, 100
116
116
  end
117
117
  end
118
118
 
119
- context "limited to 50 chars" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla...'
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.should be_summarizable_of(50)
129
+ assert_summary_to @summarized, 50
130
130
  end
131
131
  end
132
132
  end
133
133
 
134
- describe Summary, 'on tiny text' do
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
- context "by default" do
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
- @summarized.should == 'Praesent commodo. Nam nec pede. Pellentesque egestas, urna vel accumsan venenatis.'
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.should be_summarizable_of(100)
149
+ assert_summary_to @summarized, 100
150
150
  end
151
151
  end
152
152
 
153
- context "limited to 50 chars" do
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
- @summarized.should == 'Praesent commodo. Nam nec pede. Pellentesque...'
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.should be_summarizable_of(50)
163
+ assert_summary_to @summarized, 50
164
164
  end
165
165
  end
166
166
  end
167
167
 
168
168
 
169
- describe Summary, 'with different terminators' do
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
- context "limited to 50 chars" do
175
- context "with !" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla!'
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.should be_summarizable_of 50
185
+ assert_summary_to @summarized, 50
186
186
  end
187
187
  end
188
188
 
189
- context "with ." do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla.'
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.should be_summarizable_of(50)
199
+ assert_summary_to @summarized, 50
200
200
  end
201
201
  end
202
202
 
203
- context "with nothing" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec metus. Nulla sed'
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.should be_summarizable_of(50)
213
+ assert_summary_to @summarized, 50
214
214
  end
215
215
  end
216
216
 
217
- context "with html" do
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
- @summarized.should == 'Cras eleifend sodales sem. Ut nec... <a href="#read-more">read more</a>'
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.should be_summarizable_of(50)
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 File.dirname(__FILE__) + '/../lib/summary'
2
+ require 'minitest/spec'
3
3
 
4
- module Summary
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
- def be_summarizable_of(size)
18
- SummarizableOf.new(size)
19
- end
20
- end
21
- end
6
+ require File.dirname(__FILE__) + '/../lib/summary'
22
7
 
23
- begin
24
- require 'spec'
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.6.6"
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-09-04}
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", "Manifest", "README.rdoc", "Rakefile", "lib/summary.rb", "rails/init.rb", "spec/spec_helper.rb", "spec/summary_spec.rb", "summary.gemspec"]
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: 11
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 6
10
- version: 0.6.6
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-09-04 00:00:00 -03:00
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
- - Manifest
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: []