summary 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +1 -0
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile.lock +2 -3
- data/Rakefile +7 -11
- data/lib/summary.rb +3 -47
- data/lib/summary/summarize.rb +43 -0
- data/lib/summary/version.rb +8 -0
- data/spec/lib/summary_spec.rb +25 -0
- data/summary.gemspec +15 -24
- metadata +62 -59
- data/rails/init.rb +0 -1
data/.bundle/config
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--- {}
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@summary
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
summary (0.7.
|
4
|
+
summary (0.7.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
minitest (
|
9
|
+
minitest (2.3.1)
|
10
10
|
rake (0.8.7)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
13
|
ruby
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
|
-
bundler (>= 1.0.0)
|
17
16
|
minitest
|
18
17
|
rake
|
19
18
|
summary!
|
data/Rakefile
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
p.summary = '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.'
|
9
|
-
p.docs_host = 'http://azisaka.github.com/summary/doc/'
|
10
|
-
p.retain_gemspec = true
|
11
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
Rake::TestTask.new { |t| t.pattern = "spec/**/*_spec.rb" }
|
6
|
+
|
7
|
+
task :default => 'test'
|
data/lib/summary.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/summary/version"
|
2
|
+
require "#{File.dirname(__FILE__)}/summary/summarize"
|
3
|
+
|
1
4
|
module Summary
|
2
|
-
MAJOR = '0'
|
3
|
-
TINY = '7'
|
4
|
-
PATCH = '2'
|
5
|
-
VERSION = [MAJOR, TINY, PATCH] * '.'
|
6
|
-
|
7
5
|
module String
|
8
6
|
# This method sanitizes the string removing html tags, \t \n \r characters, and duplicated blank spaces.
|
9
7
|
# To use it just do:
|
@@ -25,48 +23,6 @@ module Summary
|
|
25
23
|
Summarize.new(self, size, terminator).summary
|
26
24
|
end
|
27
25
|
end
|
28
|
-
|
29
|
-
class Summarize
|
30
|
-
def initialize(text, size = 100, terminator = '...')
|
31
|
-
@text, @size, @terminator = text, size, terminator
|
32
|
-
end
|
33
|
-
|
34
|
-
# Checks the need of "summarize" the string. When it is needed, the string is splitted.
|
35
|
-
# Then the last dot is removed and the terminator is pushed into the resultant string.
|
36
|
-
def summary
|
37
|
-
return pure unless summarizable?
|
38
|
-
|
39
|
-
pure[0...string_limit].sub(/\.$/,'') + @terminator
|
40
|
-
end
|
41
|
-
|
42
|
-
protected
|
43
|
-
# It cleans up the text removing the html tags, break lines and white spaces
|
44
|
-
def pure
|
45
|
-
@pure ||= purify @text
|
46
|
-
end
|
47
|
-
|
48
|
-
# Cleans up any string removing the html tags, break lines and white spaces.
|
49
|
-
def purify(string)
|
50
|
-
string.gsub(/(^\s+)|<(.|\n)+?>|(\t|\n|\r)+/,'').sub(/\s+/,' ')
|
51
|
-
end
|
52
|
-
|
53
|
-
# Calculates the size limit to summarize the string.
|
54
|
-
def string_limit
|
55
|
-
@string_limit ||= pure[0..(@size - backspace)].rindex(' ')
|
56
|
-
end
|
57
|
-
|
58
|
-
# Verifies if the string can be summarized.
|
59
|
-
def summarizable?
|
60
|
-
pure.size > @size and pure =~ /\s/ and string_limit >= backspace
|
61
|
-
end
|
62
|
-
|
63
|
-
# Measures the space needed by the terminator.
|
64
|
-
# Let's say you want a string with 50 chars, and your terminator is a '...'.
|
65
|
-
# That means your string can only have 47 chars + 3 chars from your terminator.
|
66
|
-
def backspace
|
67
|
-
@backspace ||= purify(@terminator).size
|
68
|
-
end
|
69
|
-
end
|
70
26
|
end
|
71
27
|
|
72
28
|
String.send(:include, Summary::String)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Summary
|
2
|
+
class Summarize
|
3
|
+
def initialize(text, size = 100, terminator = '...')
|
4
|
+
@text, @size, @terminator = text, size, terminator
|
5
|
+
end
|
6
|
+
|
7
|
+
# Checks the need of "summarize" the string. When it is needed, the string is splitted.
|
8
|
+
# Then the last dot is removed and the terminator is pushed into the resultant string.
|
9
|
+
def summary
|
10
|
+
return pure unless summarizable?
|
11
|
+
|
12
|
+
pure[0...string_limit].sub(/\.$/,'') + @terminator
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
# It cleans up the text removing the html tags, break lines and white spaces
|
17
|
+
def pure
|
18
|
+
@pure ||= purify @text
|
19
|
+
end
|
20
|
+
|
21
|
+
# Cleans up any string removing the html tags, break lines and white spaces.
|
22
|
+
def purify(string)
|
23
|
+
string.gsub(/(^\s+)|<(.|\n)+?>|(\t|\n|\r)+/,'').sub(/\s+/,' ')
|
24
|
+
end
|
25
|
+
|
26
|
+
# Calculates the size limit to summarize the string.
|
27
|
+
def string_limit
|
28
|
+
@string_limit ||= pure[0..(@size - backspace)].rindex(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
# Verifies if the string can be summarized.
|
32
|
+
def summarizable?
|
33
|
+
pure.size > @size and pure =~ /\s/ and string_limit >= backspace
|
34
|
+
end
|
35
|
+
|
36
|
+
# Measures the space needed by the terminator.
|
37
|
+
# Let's say you want a string with 50 chars, and your terminator is a '...'.
|
38
|
+
# That means your string can only have 47 chars + 3 chars from your terminator.
|
39
|
+
def backspace
|
40
|
+
@backspace ||= purify(@terminator).size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/lib/summary_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
require File.expand_path("../../spec_helper", __FILE__)
|
2
3
|
|
3
4
|
describe 'Summary on plain text' do
|
@@ -230,3 +231,27 @@ describe 'Summary with different terminators' do
|
|
230
231
|
end
|
231
232
|
end
|
232
233
|
|
234
|
+
describe "Summary with accents" do
|
235
|
+
before do
|
236
|
+
@text = 'Cras eleifend sodãles sëm. Ut nec metus. Nullá sêd nisl.'
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "limited to 20 chars" do
|
240
|
+
it "should break the text" do
|
241
|
+
assert_equal 'Cras eleifend', @text.summary(20,'')
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "limited to 25 chars" do
|
246
|
+
it "should break the text" do
|
247
|
+
assert_equal 'Cras eleifend sodãles', @text.summary(25,'')
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "limited to 30 chars" do
|
252
|
+
it "should break the text" do
|
253
|
+
assert_equal 'Cras eleifend sodãles sëm. Ut', @text.summary(30,'')
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
data/summary.gemspec
CHANGED
@@ -1,30 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require "#{File.dirname(__FILE__)}/lib/summary/version"
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
5
|
+
s.name = 'summary'
|
6
|
+
s.version = Summary::Version::STRING
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = %w(Bruno Azisaka Maciel)
|
9
|
+
s.email = %w(bruno@azisaka.com.br)
|
10
|
+
s.homepage = 'http://github.com/azisaka/summary'
|
11
|
+
s.summary = "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."
|
12
|
+
s.description = "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."
|
6
13
|
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
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
|
-
s.email = %q{bruno [at] bubble [dot] com [dot] br}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/summary.rb"]
|
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
|
-
s.homepage = %q{http://github.com/azisaka/summary}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Summary", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{summary}
|
18
|
-
s.rubygems_version = %q{1.3.7}
|
19
|
-
s.summary = %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.}
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
|
+
s.require_paths = %w(lib)
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
else
|
27
|
-
end
|
28
|
-
else
|
29
|
-
end
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
s.add_development_dependency 'minitest'
|
30
21
|
end
|
metadata
CHANGED
@@ -1,85 +1,88 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: summary
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 2
|
10
|
-
version: 0.7.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.3
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
- Bruno
|
7
|
+
authors:
|
8
|
+
- Bruno
|
9
|
+
- Azisaka
|
10
|
+
- Maciel
|
14
11
|
autorequire:
|
15
12
|
bindir: bin
|
16
13
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
date: 2011-08-03 00:00:00.000000000Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
18
|
+
requirement: &2153492460 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2153492460
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: &2153492040 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2153492040
|
38
|
+
description: This is a simple gem that generates introduction text from a long text,
|
39
|
+
it will always break the text at the end of the last word near to the limit you
|
40
|
+
informed as argument.
|
41
|
+
email:
|
42
|
+
- bruno@azisaka.com.br
|
24
43
|
executables: []
|
25
|
-
|
26
44
|
extensions: []
|
27
|
-
|
28
|
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
files:
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- .bundle/config
|
48
|
+
- .gitignore
|
49
|
+
- .rvmrc
|
33
50
|
- CHANGELOG
|
34
51
|
- Gemfile
|
35
52
|
- Gemfile.lock
|
53
|
+
- Manifest
|
36
54
|
- README.rdoc
|
37
55
|
- Rakefile
|
38
56
|
- lib/summary.rb
|
39
|
-
-
|
57
|
+
- lib/summary/summarize.rb
|
58
|
+
- lib/summary/version.rb
|
40
59
|
- spec/lib/summary_spec.rb
|
41
60
|
- spec/spec_helper.rb
|
42
61
|
- summary.gemspec
|
43
|
-
- Manifest
|
44
|
-
has_rdoc: true
|
45
62
|
homepage: http://github.com/azisaka/summary
|
46
63
|
licenses: []
|
47
|
-
|
48
64
|
post_install_message:
|
49
|
-
rdoc_options:
|
50
|
-
|
51
|
-
- --inline-source
|
52
|
-
- --title
|
53
|
-
- Summary
|
54
|
-
- --main
|
55
|
-
- README.rdoc
|
56
|
-
require_paths:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
57
67
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
69
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
75
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 1
|
75
|
-
- 2
|
76
|
-
version: "1.2"
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
77
80
|
requirements: []
|
78
|
-
|
79
|
-
|
80
|
-
rubygems_version: 1.3.7
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.6
|
81
83
|
signing_key:
|
82
84
|
specification_version: 3
|
83
|
-
summary: This is a simple gem that generates introduction text from a long text, it
|
85
|
+
summary: This is a simple gem that generates introduction text from a long text, it
|
86
|
+
will always break the text at the end of the last word near to the limit you informed
|
87
|
+
as argument.
|
84
88
|
test_files: []
|
85
|
-
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/summary'
|