string_utils 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module StringUtils
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/lib/string_utils.rb CHANGED
@@ -12,6 +12,7 @@ require 'string_utils/transliteration'
12
12
  # * StringUtils.truncate("hello world", 10, "...") #=> "hello..."
13
13
  # * StringUtils.normalize_name "\302\240 Gran Via/Avda.de Asturias " #=> :Gran Via / Avda. de Asturias"
14
14
  # * StringUtils.urlify("waßer") #=> "wasser"
15
+ # * StringUtils.normalize_punctuation(" , a,,b ,") #=> "a, b"
15
16
  module StringUtils
16
17
  extend self
17
18
 
@@ -21,6 +22,19 @@ module StringUtils
21
22
  NOT_WHITESPACE = "[^\s#{NBSP}]"
22
23
  WHITESPACES = /#{WHITESPACE_MATCHER}+/
23
24
 
25
+ # Collapses spaces and commas
26
+ # Fixes spacing around the [,.;:]
27
+ # Removes trailing and leading commas
28
+ def normalize_punctuation(str)
29
+ s = str.dup
30
+ s.gsub! /\s+/, ' '
31
+ s.gsub! /\s,/, ','
32
+ s.gsub! /,+/ , ','
33
+ s.gsub! /^\s*,|,\s*$/, ''
34
+ s.gsub! /([,.;:])(\S)/, '\1 \2'
35
+ s.strip!
36
+ s
37
+ end
24
38
 
25
39
  # Converts a string to a nicely readable URL
26
40
  # opts:
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "string_utils"
3
+
4
+ describe "StringUtils" do
5
+ describe "#normalize_punctuation" do
6
+
7
+ it 'collapses commas' do
8
+ StringUtils.normalize_punctuation("a,,b").should == "a, b"
9
+ end
10
+
11
+ it 'removes leading and trailing commas' do
12
+ StringUtils.normalize_punctuation(" , ab , ").should == "ab"
13
+ end
14
+
15
+ it 'fixes spacing around commas' do
16
+ StringUtils.normalize_punctuation("a , b").should == "a, b"
17
+ end
18
+
19
+ end
20
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_utils
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gleb Mazovetskiy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-13 00:00:00 +01:00
18
+ date: 2011-02-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -92,6 +92,7 @@ files:
92
92
  - lib/string_utils/version.rb
93
93
  - string_utils.gemspec
94
94
  - test/normalize_name_spec.rb
95
+ - test/normalize_punctuation_spec.rb
95
96
  - test/truncate_spec.rb
96
97
  - test/urlify_spec.rb
97
98
  has_rdoc: true
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  requirements: []
125
126
 
126
127
  rubyforge_project: string_utils
127
- rubygems_version: 1.3.7
128
+ rubygems_version: 1.4.2
128
129
  signing_key:
129
130
  specification_version: 3
130
131
  summary: Provides useful string utils like "truncate to word"