summary 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.6.5. Code improvements and docs
2
+
1
3
  v0.6.4. [Fix #2] If the strings are smaller than the terminator it should not be applied
2
4
 
3
5
  v0.6.3. [Fix #3] Exception when the word can't be summarized
data/lib/summary.rb CHANGED
@@ -36,16 +36,10 @@ module Summary
36
36
  # Checks the need of "summarize" the string. When it is needed, the string is splitted.
37
37
  # Then the last dot is removed and the terminator is pushed into the resultant string.
38
38
  def summary
39
- return pure if pure.size < @size or pure !~ /\s/
40
-
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
39
+ return pure unless summarizable?
40
+
41
+ text = pure[0...string_limit]
42
+ text = text.gsub(/\.$/,'') + @terminator
49
43
  end
50
44
 
51
45
  protected
@@ -54,9 +48,20 @@ module Summary
54
48
  @pure ||= purify @text
55
49
  end
56
50
 
51
+ # Cleans up any string removing the html tags, break lines and white spaces.
57
52
  def purify(string)
58
53
  string.strip.gsub(/<(.|\n)+?>|(\t|\n|\r)+/,'').gsub(/\s+/,' ')
59
54
  end
55
+
56
+ # Calculates the size limit to summarize the string.
57
+ def string_limit
58
+ @string_limit ||= pure[0..(@size-backspace)].rindex(' ')
59
+ end
60
+
61
+ # Verifies if the string can be summarized.
62
+ def summarizable?
63
+ pure.size > @size and pure =~ /\s/ and string_limit >= purify(@terminator).size
64
+ end
60
65
 
61
66
  # Measures the space needed by the terminator.
62
67
  # Let's say you want a string with 50 chars, and your terminator is a '...'.
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.4"
5
+ s.version = "0.6.5"
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 4
10
- version: 0.6.4
9
+ - 5
10
+ version: 0.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bruno Azisaka Maciel
metadata.gz.sig CHANGED
Binary file