string_case_pl 0.0.5 → 0.0.6

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.
@@ -1,51 +1,66 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  class String
4
+ UTF_8_ENCODING = "UTF-8"
5
+ ISO_8859_2_ENCODING = "ISO-8859-2"
6
+ WINDOWS_CP1250_ENCODING = "Windows-1250"
4
7
  # old up/down-case without Polish transcodings
5
8
  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")
9
+ "\xc4\x87\xc5\x84\xc3\xb3\xc5\x82").force_encoding(UTF_8_ENCODING)
7
10
  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
11
+ "\xc4\x86\xc5\x83\xc3\x93\xc5\x81").force_encoding(UTF_8_ENCODING)
12
+ PL_ISO_8859_2_LOWER = PL_UTF_8_LOWER.encode(ISO_8859_2_ENCODING)
13
+ PL_ISO_8859_2_UPPER = PL_UTF_8_UPPER.encode(ISO_8859_2_ENCODING)
14
+ PL_WINDOWS_1250_LOWER = PL_UTF_8_LOWER.encode(WINDOWS_CP1250_ENCODING)
15
+ PL_WINDOWS_1250_UPPER = PL_UTF_8_UPPER.encode(WINDOWS_CP1250_ENCODING)
16
+
17
+ alias old_downcase_wo_pl downcase!
18
+ alias old_upcase_wo_pl upcase!
16
19
  alias old_capitalize_wo_pl capitalize
17
20
 
18
- def downcase
21
+ def downcase!
19
22
  case self.encoding.name
20
- when "UTF-8"
23
+ when UTF_8_ENCODING
21
24
  self.tr!(PL_UTF_8_UPPER,PL_UTF_8_LOWER)
22
- when "ISO-8859-2"
25
+ when ISO_8859_2_ENCODING
23
26
  self.tr!(PL_ISO_8859_2_UPPER, PL_ISO_8859_2_LOWER)
24
- when "Windows-1250"
27
+ when WINDOWS_CP1250_ENCODING
25
28
  self.tr!(PL_WINDOWS_1250_UPPER, PL_WINDOWS_1250_LOWER)
26
29
  end
27
30
  self.old_downcase_wo_pl
28
31
  end
29
32
 
30
- def upcase
33
+ def downcase
34
+ str = self.dup
35
+ str.downcase!
36
+ str
37
+ end
38
+
39
+ def upcase!
31
40
  case self.encoding.name
32
- when "UTF-8"
41
+ when UTF_8_ENCODING
33
42
  self.tr!(PL_UTF_8_LOWER, PL_UTF_8_UPPER)
34
- when "ISO-8859-2"
43
+ when ISO_8859_2_ENCODING
35
44
  self.tr!(PL_ISO_8859_2_LOWER, PL_ISO_8859_2_UPPER)
36
- when "Windows-1250"
45
+ when WINDOWS_CP1250_ENCODING
37
46
  self.tr!(PL_WINDOWS_1250_LOWER, PL_WINDOWS_1250_UPPER)
38
47
  end
39
48
  self.old_upcase_wo_pl
40
49
  end
41
-
50
+
51
+ def upcase
52
+ str = self.dup
53
+ str.upcase!
54
+ str
55
+ end
56
+
42
57
  def capitalize
43
58
  s = self.dup
44
59
  s[0] = s[0].upcase
45
60
  s[1..-1] = s[1..-1].downcase
46
61
  s
47
62
  end
48
-
63
+
49
64
  def capitalize!
50
65
  old = self.dup
51
66
  self[0..-1] = self.capitalize
@@ -53,3 +68,4 @@ class String
53
68
  end
54
69
 
55
70
  end
71
+
@@ -1,11 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "string_case_pl"
3
- s.version = "0.0.5"
4
- s.date = "2009-12-27"
3
+ s.version = "0.0.6"
4
+ s.required_ruby_version = '>= 1.9.2'
5
+ s.date = "2011-08-02"
5
6
  s.summary = "Additional support for Polish encodings in Ruby 1.9"
6
7
  s.email = "apohllo@o2.pl"
7
8
  s.homepage = "http://apohllo.pl/blog"
8
- s.description = "Polish extensions for Ruby 1.9 String #upcase, #downcase and #capitalize supporting polish diacritics"
9
+ s.description = "Polish extensions for Ruby 1.9 String #upcase(!), #downcase(!) and #capitalize(!) supporting polish diacritics"
9
10
  s.require_path = "lib"
10
11
  s.has_rdoc = false
11
12
  s.authors = ['Aleksander Pohl']
@@ -38,23 +38,112 @@ class TestCharacterCaseChange < Test::Unit::TestCase
38
38
  def test_windows_1250_upcase
39
39
  assert_equal(@windows_upper, @windows_lower.upcase)
40
40
  end
41
-
41
+
42
42
  def test_utf_8_capitalize
43
43
  assert_equal(@utf_capitalized, @utf_lower.capitalize)
44
44
  end
45
-
45
+
46
46
  def test_windows_1250_capitalize
47
47
  assert_equal(@windows_capitalized, @windows_lower.capitalize)
48
48
  end
49
-
49
+
50
50
  def test_iso_8859_2_capitalize
51
51
  assert_equal(@iso_capitalized, @iso_lower.capitalize)
52
52
  end
53
-
53
+
54
+ def test_preserve_utf_lower_case
55
+ original = @utf_lower.dup
56
+ @utf_lower.upcase
57
+ assert_equal(original,@utf_lower)
58
+ end
59
+
60
+ def test_preserve_utf_upper_case
61
+ original = @utf_upper.dup
62
+ @utf_upper.downcase
63
+ assert_equal(original,@utf_upper)
64
+ end
65
+
66
+ def test_preserve_iso_lower_case
67
+ original = @iso_lower.dup
68
+ @iso_lower.upcase
69
+ assert_equal(original,@iso_lower)
70
+ end
71
+
72
+ def test_preserve_iso_upper_case
73
+ original = @iso_upper.dup
74
+ @iso_upper.downcase
75
+ assert_equal(original,@iso_upper)
76
+ end
77
+
78
+ def test_preserve_windows_lower_case
79
+ original = @windows_lower.dup
80
+ @windows_lower.upcase
81
+ assert_equal(original,@windows_lower)
82
+ end
83
+
84
+ def test_preserve_windows_upper_case
85
+ original = @windows_upper.dup
86
+ @windows_upper.downcase
87
+ assert_equal(original,@windows_upper)
88
+ end
89
+
90
+ def test_same_case
91
+ copy = @utf_lower.dup
92
+ assert_equal(@utf_lower,copy.downcase)
93
+ end
94
+
95
+ def test_same_case_bang
96
+ copy = @utf_lower.dup
97
+ assert_equal(nil,copy.downcase!)
98
+ assert_equal(copy,@utf_lower)
99
+ end
100
+
101
+ def test_change_utf_lower_case
102
+ copy = @utf_lower.dup
103
+ copy.upcase!
104
+ assert_equal(copy,@utf_upper)
105
+ end
106
+
107
+ def test_change_utf_upper_case
108
+ copy = @utf_upper.dup
109
+ copy.downcase!
110
+ assert_equal(copy,@utf_lower)
111
+ end
112
+
113
+ def test_change_iso_lower_case
114
+ copy = @iso_lower.dup
115
+ copy.upcase!
116
+ assert_equal(copy,@iso_upper)
117
+ end
118
+
119
+ def test_change_iso_upper_case
120
+ copy = @iso_upper.dup
121
+ copy.downcase!
122
+ assert_equal(copy,@iso_lower)
123
+ end
124
+
125
+ def test_change_windows_lower_case
126
+ copy = @windows_lower.dup
127
+ copy.upcase!
128
+ assert_equal(copy,@windows_upper)
129
+ end
130
+
131
+ def test_change_windows_upper_case
132
+ copy = @windows_upper.dup
133
+ copy.downcase!
134
+ assert_equal(copy,@windows_lower)
135
+ end
136
+
137
+ def test_capitalize
138
+ original = @utf_lower.dup
139
+ assert_equal(original.capitalize, @utf_capitalized)
140
+ assert_equal(original, @utf_lower)
141
+ end
142
+
54
143
  def test_capitalize!
55
- d = @utf_lower.dup
56
- assert_equal(d.capitalize!, @utf_capitalized)
57
- assert_equal(d.capitalize!, nil)
144
+ copy = @utf_lower.dup
145
+ assert_equal(copy.capitalize!, @utf_capitalized)
146
+ assert_equal(copy.capitalize!, nil)
58
147
  end
59
-
148
+
60
149
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_case_pl
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
4
+ prerelease:
5
+ version: 0.0.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Aleksander Pohl
@@ -14,11 +10,10 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2009-12-27 00:00:00 +01:00
18
- default_executable:
13
+ date: 2011-08-02 00:00:00 Z
19
14
  dependencies: []
20
15
 
21
- description: "Polish extensions for Ruby 1.9 String #upcase, #downcase and #capitalize supporting polish diacritics"
16
+ description: "Polish extensions for Ruby 1.9 String #upcase(!), #downcase(!) and #capitalize(!) supporting polish diacritics"
22
17
  email: apohllo@o2.pl
23
18
  executables: []
24
19
 
@@ -32,7 +27,6 @@ files:
32
27
  - lib/string_case_pl.rb
33
28
  - test/test_character_case_change.rb
34
29
  - test/test_helper.rb
35
- has_rdoc: true
36
30
  homepage: http://apohllo.pl/blog
37
31
  licenses: []
38
32
 
@@ -46,21 +40,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
40
  requirements:
47
41
  - - ">="
48
42
  - !ruby/object:Gem::Version
49
- segments:
50
- - 0
51
- version: "0"
43
+ version: 1.9.2
52
44
  required_rubygems_version: !ruby/object:Gem::Requirement
53
45
  none: false
54
46
  requirements:
55
47
  - - ">="
56
48
  - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
49
  version: "0"
60
50
  requirements: []
61
51
 
62
52
  rubyforge_project:
63
- rubygems_version: 1.3.7
53
+ rubygems_version: 1.8.5
64
54
  signing_key:
65
55
  specification_version: 3
66
56
  summary: Additional support for Polish encodings in Ruby 1.9