string_utils 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p125@string_utils"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in string_utils.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,30 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- string_utils (1.0.4)
4
+ string_utils (1.0.7)
5
5
  activesupport (>= 2.3.5)
6
6
  i18n
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activesupport (3.0.3)
12
- diff-lcs (1.1.2)
13
- i18n (0.5.0)
14
- rspec (2.2.0)
15
- rspec-core (~> 2.2)
16
- rspec-expectations (~> 2.2)
17
- rspec-mocks (~> 2.2)
18
- rspec-core (2.2.1)
19
- rspec-expectations (2.2.0)
20
- diff-lcs (~> 1.1.2)
21
- rspec-mocks (2.2.0)
11
+ activesupport (3.2.3)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ diff-lcs (1.1.3)
15
+ i18n (0.6.0)
16
+ multi_json (1.3.2)
17
+ rspec (2.9.0)
18
+ rspec-core (~> 2.9.0)
19
+ rspec-expectations (~> 2.9.0)
20
+ rspec-mocks (~> 2.9.0)
21
+ rspec-core (2.9.0)
22
+ rspec-expectations (2.9.1)
23
+ diff-lcs (~> 1.1.3)
24
+ rspec-mocks (2.9.0)
22
25
 
23
26
  PLATFORMS
24
27
  ruby
25
28
 
26
29
  DEPENDENCIES
27
- activesupport (>= 2.3.5)
28
- i18n
29
30
  rspec (>= 2.0.0)
30
31
  string_utils!
data/lib/string_utils.rb CHANGED
@@ -24,15 +24,28 @@ module StringUtils
24
24
  WHITESPACES = /#{WHITESPACE_MATCHER}+/
25
25
 
26
26
  # Collapses spaces and commas
27
- # Fixes spacing around the [,.;:]
27
+ # Fixes spacing around the following characters:
28
+ # ,.;:&
29
+ # Removes consecutive character dupes
28
30
  # Removes trailing and leading commas
29
31
  def normalize_punctuation(str)
30
32
  s = str.dup
31
33
  s.gsub! /\s+/, ' '
32
- s.gsub! /\s,/, ','
33
- s.gsub! /,+/ , ','
34
- s.gsub! /^\s*,|,\s*$/, ''
34
+
35
+ s.gsub(/\s*&,/)
36
+
37
+ # Collapse w/s around all
38
+ s.gsub! /\s*([:,&.;])\s*/, '\1'
39
+ # Collapse consecutive dupes
40
+ s.gsub! /([.,;&:])+/ , '\1'
41
+
42
+ # Collapse leading and trailing punctuation
43
+ s.gsub! /^\s*[,:&;.]|[.;&:,]\s*$/, ''
44
+
45
+ # Add whitespaces
35
46
  s.gsub! /([,.;:])(\S)/, '\1 \2'
47
+ s.gsub! /(\S)([&])(\S)/, '\1 \2 \3'
48
+
36
49
  s.strip!
37
50
  s
38
51
  end
@@ -1,3 +1,3 @@
1
1
  module StringUtils
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -1,20 +1,39 @@
1
1
  # -*- coding: utf-8 -*-
2
- require "string_utils"
2
+ require 'string_utils'
3
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"
4
+ describe 'StringUtils' do
5
+ describe '#normalize_punctuation' do
6
+ describe 'removes trailing and leading:' do
7
+ it 'commas' do
8
+ StringUtils.normalize_punctuation(' , ab , ').should == 'ab'
9
+ end
9
10
  end
10
-
11
- it 'removes leading and trailing commas' do
12
- StringUtils.normalize_punctuation(" , ab , ").should == "ab"
11
+
12
+ describe 'transforms whitespace to 0 left-side and 1 right-side whitespace characters'do
13
+ it 'commas' do
14
+ StringUtils.normalize_punctuation('a , b').should == 'a, b'
15
+ StringUtils.normalize_punctuation('a ,b').should == 'a, b'
16
+ StringUtils.normalize_punctuation('a,b').should == 'a, b'
17
+ end
18
+
19
+ it 'normalizes whitespace around semicolons (:)' do
20
+ StringUtils.normalize_punctuation('a : b').should == 'a: b'
21
+ StringUtils.normalize_punctuation('a :b').should == 'a: b'
22
+ StringUtils.normalize_punctuation('a:b').should == 'a: b'
23
+ end
24
+
25
+ it 'normalizes whitespace around ampersands (&)' do
26
+ StringUtils.normalize_punctuation('a&b').should == 'a & b'
27
+ StringUtils.normalize_punctuation('a & b').should == 'a & b'
28
+ StringUtils.normalize_punctuation('a &b').should == 'a & b'
29
+ StringUtils.normalize_punctuation('a& b').should == 'a & b'
30
+ end
13
31
  end
14
32
 
15
- it 'fixes spacing around commas' do
16
- StringUtils.normalize_punctuation("a , b").should == "a, b"
33
+ describe 'collapses consecutive:' do
34
+ it 'commas' do
35
+ StringUtils.normalize_punctuation('a,,b').should == 'a, b'
36
+ end
17
37
  end
18
-
19
38
  end
20
39
  end
metadata CHANGED
@@ -1,70 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: string_utils
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
4
5
  prerelease:
5
- version: 1.0.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Gleb Mazovetskiy
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-11 00:00:00 +02:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: activesupport
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &6177300 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 2.3.5
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: i18n
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *6177300
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &6176140 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rspec
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *6176140
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &6174960 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
46
43
  version: 2.0.0
47
44
  type: :development
48
- version_requirements: *id003
49
- description: |
50
- Provides useful string utils like "truncate to word".
51
- Compatible with ruby >= 1.8. Benefits from active_support if available on ruby < 1.9.
52
-
53
- Tested with:
54
-
55
- * ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2010.02
56
- *
57
-
58
- email:
45
+ prerelease: false
46
+ version_requirements: *6174960
47
+ description: ! "Provides useful string utils like \"truncate to word\".\nCompatible
48
+ with ruby >= 1.8. Benefits from active_support if available on ruby < 1.9.\n\nTested
49
+ with:\n\n * ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0x8770,
50
+ Ruby Enterprise Edition 2010.02\n * \n"
51
+ email:
59
52
  - glex.spb@gmail.com
60
53
  executables: []
61
-
62
54
  extensions: []
63
-
64
55
  extra_rdoc_files: []
65
-
66
- files:
56
+ files:
67
57
  - .gitignore
58
+ - .rvmrc
68
59
  - Gemfile
69
60
  - Gemfile.lock
70
61
  - README
@@ -77,33 +68,28 @@ files:
77
68
  - test/normalize_punctuation_spec.rb
78
69
  - test/truncate_spec.rb
79
70
  - test/urlify_spec.rb
80
- has_rdoc: true
81
71
  homepage: http://github.com/glebm/string_utils
82
72
  licenses: []
83
-
84
73
  post_install_message:
85
74
  rdoc_options: []
86
-
87
- require_paths:
75
+ require_paths:
88
76
  - lib
89
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
90
78
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
84
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
101
89
  requirements: []
102
-
103
90
  rubyforge_project: string_utils
104
- rubygems_version: 1.6.2
91
+ rubygems_version: 1.8.17
105
92
  signing_key:
106
93
  specification_version: 3
107
94
  summary: Provides useful string utils like "truncate to word"
108
95
  test_files: []
109
-