string_case_pl 0.0.2

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/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ task :default => [:test]
2
+
3
+ $gem_name = "string_case_pl"
4
+
5
+ desc "Build the gem"
6
+ task :build do
7
+ sh "gem build #$gem_name.gemspec"
8
+ end
9
+
10
+ desc "Install the library at local machnie"
11
+ task :install => :build do
12
+ sh "sudo gem install #$gem_name"
13
+ end
14
+
15
+ desc "Uninstall the library from local machnie"
16
+ task :uninstall do
17
+ sh "sudo gem uninstall #$gem_name"
18
+ end
19
+
20
+ desc "Run tests"
21
+ task :test do
22
+ sh "ruby test/*"
23
+ end
24
+
25
+ desc "Clean"
26
+ task :clean do
27
+ sh "rm #$gem_name*.gem"
28
+ end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class String
4
+ # old up/down-case without Polish transcodings
5
+ PL_UTF_8_LOWER = ("\xc4\x85\xc5\xbc\xc5\x9b\xc5\xba\xc4\x99" +
6
+ "\xc4\x87\xc5\x84\xc3\xb3\xc5\x82").force_encoding("UTF-8")
7
+ PL_UTF_8_UPPER = ("\xc4\x84\xc5\xbb\xc5\x9a\xc5\xb9\xc4\x98" +
8
+ "\xc4\x86\xc5\x83\xc3\x93\xc5\x81").force_encoding("UTF-8")
9
+ PL_ISO_8859_2_LOWER = PL_UTF_8_LOWER.encode("ISO-8859-2")
10
+ PL_ISO_8859_2_UPPER = PL_UTF_8_UPPER.encode("ISO-8859-2")
11
+ PL_WINDOWS_1250_LOWER = PL_UTF_8_LOWER.encode("Windows-1250")
12
+ PL_WINDOWS_1250_UPPER = PL_UTF_8_UPPER.encode("Windows-1250")
13
+
14
+ alias old_downcase_wo_pl downcase
15
+ alias old_upcase_wo_pl upcase
16
+
17
+ def downcase
18
+ case self.encoding.name
19
+ when "UTF-8"
20
+ self.tr!(PL_UTF_8_UPPER,PL_UTF_8_LOWER)
21
+ when "ISO-8859-2"
22
+ self.tr!(PL_ISO_8859_2_UPPER, PL_ISO_8859_2_LOWER)
23
+ when "Windows-1250"
24
+ self.tr!(PL_WINDOWS_1250_UPPER, PL_WINDOWS_1250_LOWER)
25
+ end
26
+ self.old_downcase_wo_pl
27
+ end
28
+
29
+ def upcase
30
+ case self.encoding.name
31
+ when "UTF-8"
32
+ self.tr!(PL_UTF_8_LOWER, PL_UTF_8_UPPER)
33
+ when "ISO-8859-2"
34
+ self.tr!(PL_ISO_8859_2_LOWER, PL_ISO_8859_2_UPPER)
35
+ when "Windows-1250"
36
+ self.tr!(PL_WINDOWS_1250_LOWER, PL_WINDOWS_1250_UPPER)
37
+ end
38
+ self.old_upcase_wo_pl
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "string_case_pl"
3
+ s.version = "0.0.2"
4
+ s.date = "2009-12-27"
5
+ s.summary = "Additional support for Polish encodings in Ruby 1.9"
6
+ s.email = "apohllo@o2.pl"
7
+ s.homepage = "http://apohllo.pl/blog"
8
+ s.description = "Polish extensions for Ruby 1.9 String #upcase and #downcase supporting polish diacritics"
9
+ s.require_path = "lib"
10
+ s.has_rdoc = false
11
+ s.authors = ['Aleksander Pohl']
12
+ s.files = ["Rakefile", "string_case_pl.gemspec", 'lib/string_case_pl.rb'] +
13
+ Dir.glob("lib/**/*")
14
+ s.test_files = Dir.glob("{test}/**/*")
15
+ #s.rdoc_options = ["--main", "README.txt"]
16
+ #s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
17
+ end
18
+
19
+
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
3
+
4
+ class TestCharacterCaseChange < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @utf_lower = "ąćęłńóśżźabcdefghijklmnopqrstuvwxyz".force_encoding("UTF-8")
8
+ @utf_upper = "ĄĆĘŁŃÓŚŻŹABCDEFGHIJKLMNOPQRSTUVWXYZ".force_encoding("UTF-8")
9
+ @iso_lower = "\xb1\xe6\xea\xb3\xf1\xf3\xb6\xbf\xbcabcdefghijklmnopqrstuvwxyz".force_encoding("ISO-8859-2")
10
+ @iso_upper = "\xa1\xc6\xca\xa3\xd1\xd3\xa6\xaf\xacABCDEFGHIJKLMNOPQRSTUVWXYZ".force_encoding("ISO-8859-2")
11
+ @windows_lower = "\xb9\xe6\xea\xb3\xf1\xf3\x9c\xbf\x9fabcdefghijklmnopqrstuvwxyz".force_encoding("Windows-1250")
12
+ @windows_upper = "\xa5\xc6\xca\xa3\xd1\xd3\x8c\xaf\x8fABCDEFGHIJKLMNOPQRSTUVWXYZ".force_encoding("Windows-1250")
13
+ end
14
+
15
+ def test_utf_8_downcase
16
+ assert_equal(@utf_lower, @utf_upper.downcase)
17
+ end
18
+
19
+ def test_utf_8_upcase
20
+ assert_equal(@utf_upper, @utf_lower.upcase)
21
+ end
22
+
23
+ def test_iso_8859_2_downcase
24
+ assert_equal(@iso_lower, @iso_upper.downcase)
25
+ end
26
+
27
+ def test_iso_8859_2_upcase
28
+ assert_equal(@iso_upper, @iso_lower.upcase)
29
+ end
30
+
31
+ def test_windows_1250_downcase
32
+ assert_equal(@windows_lower, @windows_upper.downcase)
33
+ end
34
+
35
+ def test_windows_1250_upcase
36
+ assert_equal(@windows_upper, @windows_lower.upcase)
37
+ end
38
+ end
39
+
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'test/unit'
4
+ require 'string_case_pl'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string_case_pl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Aleksander Pohl
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2009-12-27 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: "Polish extensions for Ruby 1.9 String #upcase and #downcase supporting polish diacritics"
22
+ email: apohllo@o2.pl
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - string_case_pl.gemspec
32
+ - lib/string_case_pl.rb
33
+ - test/test_character_case_change.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: true
36
+ homepage: http://apohllo.pl/blog
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Additional support for Polish encodings in Ruby 1.9
67
+ test_files:
68
+ - test/test_character_case_change.rb
69
+ - test/test_helper.rb