summary 0.6.3 → 0.6.4

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.6.4. [Fix #2] If the strings are smaller than the terminator it should not be applied
2
+
1
3
  v0.6.3. [Fix #3] Exception when the word can't be summarized
2
4
 
3
5
  v0.6.2. README review
data/lib/summary.rb CHANGED
@@ -38,21 +38,31 @@ module Summary
38
38
  def summary
39
39
  return pure if pure.size < @size or pure !~ /\s/
40
40
 
41
- @text = pure[0...pure[0..(@size-backspace)].rindex(' ')]
42
- @text.gsub(/\.$/,'') + @terminator
41
+ limit = pure[0..(@size-backspace)].rindex(' ')
42
+
43
+ if limit >= purify(@terminator).size
44
+ text = pure[0...limit]
45
+ text = text.gsub(/\.$/,'') + @terminator
46
+ else
47
+ pure
48
+ end
43
49
  end
44
50
 
45
51
  protected
46
52
  # It cleans up the text removing the html tags, break lines and white spaces
47
53
  def pure
48
- @pure ||= @text.strip.gsub(/<(.|\n)+?>|(\t|\n|\r)+/,'').gsub(/\s+/,' ')
54
+ @pure ||= purify @text
55
+ end
56
+
57
+ def purify(string)
58
+ string.strip.gsub(/<(.|\n)+?>|(\t|\n|\r)+/,'').gsub(/\s+/,' ')
49
59
  end
50
60
 
51
61
  # Measures the space needed by the terminator.
52
62
  # Let's say you want a string with 50 chars, and your terminator is a '...'.
53
63
  # That means your string can only have 47 chars + 3 chars from your terminator.
54
64
  def backspace
55
- (@terminator =~ /<(.|\n)+?>/ ? @terminator.gsub(/<(.|\n)+?>/,'') : @terminator).size
65
+ (@terminator =~ /<(.|\n)+?>/ ? purify(@terminator) : @terminator).size
56
66
  end
57
67
  end
58
68
  end
data/spec/summary_spec.rb CHANGED
@@ -34,7 +34,7 @@ describe Summary, 'on plain text' do
34
34
  end
35
35
  end
36
36
 
37
- describe Summary, "when the string is thin" do
37
+ describe Summary, "when the string is a word" do
38
38
  before do
39
39
  @text = "test"
40
40
  end
@@ -46,6 +46,16 @@ describe Summary, "when the string is thin" do
46
46
  end
47
47
  end
48
48
 
49
+ describe Summary, "when the terminator is bigger" do
50
+ before do
51
+ @text = "test test"
52
+ end
53
+
54
+ it "should not summarize the string" do
55
+ @text.summary(4, '.' * 5).should == @text
56
+ end
57
+ end
58
+
49
59
  describe Summary, 'on html' do
50
60
  before do
51
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.'
data/summary.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{summary}
5
- s.version = "0.6.3"
5
+ s.version = "0.6.4"
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"]
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: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bruno Azisaka Maciel
metadata.gz.sig CHANGED
Binary file