string_normalizr 0.2 → 0.3

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/Manifest CHANGED
@@ -1,8 +1,9 @@
1
1
  LICENSE
2
2
  README.rdoc
3
3
  Rakefile
4
+ VERSION
4
5
  init.rb
5
6
  lib/string_normalizr.rb
6
- nbproject/private/rake-d.txt
7
+ string_normalizr.gemspec
7
8
  test/string_normalizr_test.rb
8
9
  Manifest
@@ -21,6 +21,7 @@ Or use it as a plugin with your Rails app:
21
21
  * handle punctuation marks
22
22
 
23
23
  === Changelog
24
+ * 0.3: Added normalize! for in-place normalization and activated downcase option
24
25
  * 0.2: Normalization can now be customized via an options hash.
25
26
  * 0.1: Initial version
26
27
 
data/Rakefile CHANGED
@@ -9,12 +9,14 @@ Rake::TestTask.new("test") do |t|
9
9
  t.verbose = false
10
10
  end
11
11
 
12
- Echoe.new('string_normalizr', '0.2') do |p|
12
+ version = File.read("./VERSION")
13
+
14
+ Echoe.new('string_normalizr', version) do |p|
13
15
  p.description = "Let String instances be conviently normalized"
14
16
  p.url = "http://github.com/carpodaster/string_normalizr"
15
17
  p.author = "Carsten Zimmermann"
16
18
  p.email = "carp@hacksocke.de"
17
- p.ignore_pattern = ["tmp/*", "script/*", "nbproject/*"]
19
+ p.ignore_pattern = ["tmp/*", "script/*", "nbproject/*", "nbproject/private/*"]
18
20
  p.development_dependencies = []
19
21
  end
20
22
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3
@@ -71,6 +71,7 @@ module AegisNet # :nodoc:
71
71
  # * +options+: optional Hash for normalization customization
72
72
  #
73
73
  # == Available options
74
+ # * <tt>:downcase</tt> - convert to lower case (true|false, default: false)
74
75
  # * <tt>:strip</tt> - trim leading and trailing whitespaces (true|false, default: true)
75
76
  # * <tt>:replace_whitespaces</tt> - replace whitespaces within the string with +str+
76
77
  # or set to +false+ to leave whitespaces alone. Makes little
@@ -85,7 +86,7 @@ module AegisNet # :nodoc:
85
86
  #
86
87
  def normalize(options = {})
87
88
  # shamelessly taken from ActiveSupport::ActiveSupport::Hash::Keys#assert_valid_keys
88
- valid_keys = [:replace_whitespaces, :strip]
89
+ valid_keys = [:downcase, :replace_whitespaces, :strip]
89
90
  unknown_keys = options.keys - [valid_keys].flatten
90
91
  raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
91
92
 
@@ -98,9 +99,19 @@ module AegisNet # :nodoc:
98
99
 
99
100
  n_str = AegisNet::StringNormalizr::COLLATION.inject(dup) {|str, (collate_from, collate_to)| str.gsub(collate_from, collate_to)}
100
101
  n_str.strip! if options[:strip]
102
+ n_str.downcase! if options[:downcase]
101
103
  n_str.gsub!(/\s+/, options[:replace_whitespaces]) if options[:replace_whitespaces]
102
104
  n_str
103
105
  end
106
+
107
+ # Performs the changes of AegisNet::StringNormalizr#normalize in place,
108
+ # returning the new string.
109
+ #
110
+ # See AegisNet::StringNormalizr#normalize for the optional parameter hash.
111
+ def normalize!(options = {})
112
+ self.replace(self.normalize(options))
113
+ end
114
+
104
115
  end
105
116
  end
106
117
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{string_normalizr}
5
- s.version = "0.2"
5
+ s.version = "0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Carsten Zimmermann"]
9
- s.date = %q{2010-09-20}
9
+ s.date = %q{2010-10-12}
10
10
  s.description = %q{Let String instances be conviently normalized}
11
11
  s.email = %q{carp@hacksocke.de}
12
12
  s.extra_rdoc_files = ["LICENSE", "README.rdoc", "lib/string_normalizr.rb"]
13
- s.files = ["LICENSE", "README.rdoc", "Rakefile", "init.rb", "lib/string_normalizr.rb", "nbproject/private/rake-d.txt", "test/string_normalizr_test.rb", "Manifest", "string_normalizr.gemspec"]
13
+ s.files = ["LICENSE", "README.rdoc", "Rakefile", "VERSION", "init.rb", "lib/string_normalizr.rb", "string_normalizr.gemspec", "test/string_normalizr_test.rb", "Manifest"]
14
14
  s.homepage = %q{http://github.com/carpodaster/string_normalizr}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "String_normalizr", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -17,6 +17,18 @@ class StringNormalizrTest < Test::Unit::TestCase
17
17
  assert_equal "foo \n \t", "foo \n \t".normalize(:strip => false, :replace_whitespaces => false)
18
18
  end
19
19
 
20
+ def test_downcase
21
+ assert_equal "this-is-an-example", "This is an Example".normalize(:downcase => true)
22
+
23
+ end
24
+
25
+ def test_bang
26
+ foo = "some stríng"
27
+ assert foo.respond_to?(:normalize!)
28
+ foo.normalize!
29
+ assert_equal "some-string", foo
30
+ end
31
+
20
32
  def test_accents
21
33
  assert_equal "a", "á".normalize
22
34
  assert_equal "a", "à".normalize
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_normalizr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Carsten Zimmermann
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-20 00:00:00 +02:00
17
+ date: 2010-10-12 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,12 +32,12 @@ files:
32
32
  - LICENSE
33
33
  - README.rdoc
34
34
  - Rakefile
35
+ - VERSION
35
36
  - init.rb
36
37
  - lib/string_normalizr.rb
37
- - nbproject/private/rake-d.txt
38
+ - string_normalizr.gemspec
38
39
  - test/string_normalizr_test.rb
39
40
  - Manifest
40
- - string_normalizr.gemspec
41
41
  has_rdoc: true
42
42
  homepage: http://github.com/carpodaster/string_normalizr
43
43
  licenses: []
File without changes