polskie_stringi 0.0.1
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/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +54 -0
- data/init.rb +3 -0
- data/lib/polskie_stringi.rb +55 -0
- data/test/polskie_stringi_test.rb +22 -0
- data/test/test_helper.rb +5 -0
- metadata +70 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 v1x100r
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
PolskieStringi
|
2
|
+
==============
|
3
|
+
|
4
|
+
Rozszerzenie klasy String, naprawiające metody upcase, downcase i capitalize aby działały dla polskich znaków. dodana też metoda no_pl zamieniająca polskie litery na ich odpowiedniki w kodach ASCII. Dla każdej z funkcji istnieją ich odpowiedniki z !, np upcase! no_pl! itp
|
5
|
+
|
6
|
+
|
7
|
+
Example
|
8
|
+
=======
|
9
|
+
|
10
|
+
Example goes here.
|
11
|
+
|
12
|
+
|
13
|
+
Copyright (c) 2011 v1x100r, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Test the polskie_stringi plugin.'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Generate documentation for the polskie_stringi plugin.'
|
20
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'PolskieStringi'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
PKG_FILES = FileList[
|
29
|
+
'[a-zA-Z]*',
|
30
|
+
'generators/**/*',
|
31
|
+
'lib/**/*',
|
32
|
+
'rails/**/*',
|
33
|
+
'tasks/**/*',
|
34
|
+
'test/**/*'
|
35
|
+
]
|
36
|
+
|
37
|
+
spec = Gem::Specification.new do |s|
|
38
|
+
s.name = "polskie_stringi"
|
39
|
+
s.version = "0.0.1"
|
40
|
+
s.author = "v1x100r"
|
41
|
+
s.email = "v1x100r@gmail.com"
|
42
|
+
s.homepage = ""
|
43
|
+
s.platform = Gem::Platform::RUBY
|
44
|
+
s.summary = "Rozszerza funkcje klasy String o obsługę polskich znaków"
|
45
|
+
s.files = PKG_FILES.to_a
|
46
|
+
s.require_path = "lib"
|
47
|
+
s.has_rdoc = false
|
48
|
+
s.extra_rdoc_files = ["README"]
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Turn this plugin into a gem.'
|
52
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
53
|
+
pkg.gem_spec = spec
|
54
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class ::String
|
4
|
+
|
5
|
+
def upcase
|
6
|
+
# znajdź małe litery w łańcuchu, wyszukaj ich indeks w tablicy małych liter i podmień na wartość z tablicy dużych liter
|
7
|
+
gsub(/[a-z#{String.polish_chars('small').join('')}]/) { |s| (('A'..'Z').to_a + String.polish_chars('big'))[(('a'..'z').to_a + String.polish_chars('small')).index(s)] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def downcase
|
11
|
+
# jak wyżej, ale odwrotnie
|
12
|
+
gsub(/[A-Z#{String.polish_chars('big').join('')}]/) { |s| (('a'..'z').to_a + String.polish_chars('small'))[(('A'..'Z').to_a + String.polish_chars('big')).index(s)] }
|
13
|
+
end
|
14
|
+
|
15
|
+
def no_pl
|
16
|
+
# jak wyżej, ale tablicami są polskie znaki małe i duże, oraz ich odpowiedniki ASCII
|
17
|
+
gsub(/[#{String.polish_chars.join('')}]/) { |s| %w[a e s c z z o l n A E S C Z Z O L N][String.polish_chars.index(s)] }
|
18
|
+
end
|
19
|
+
|
20
|
+
def no_pl!
|
21
|
+
replace no_pl
|
22
|
+
end
|
23
|
+
|
24
|
+
# pierwsza litera upcase, reszta downcase
|
25
|
+
def capitalize
|
26
|
+
self[0].to_s.upcase + self[1..size].to_s.downcase
|
27
|
+
end
|
28
|
+
|
29
|
+
def upcase!
|
30
|
+
replace upcase
|
31
|
+
end
|
32
|
+
|
33
|
+
def downcase!
|
34
|
+
replace downcase
|
35
|
+
end
|
36
|
+
|
37
|
+
def capitalize!
|
38
|
+
replace capitalize
|
39
|
+
end
|
40
|
+
|
41
|
+
# polskie znaki, np do użycia z regexp
|
42
|
+
# ('small' => tylko małe, 'big' => tylko duże, 'all' lub pusty => wszystkie)
|
43
|
+
def self.polish_chars(size = 'all')
|
44
|
+
small = %w[ą ę ś ć ź ż ó ł ń]
|
45
|
+
big = %w[Ą Ę Ś Ć Ź Ż Ó Ł Ń]
|
46
|
+
case size
|
47
|
+
when 'small'
|
48
|
+
small
|
49
|
+
when 'big'
|
50
|
+
big
|
51
|
+
else
|
52
|
+
small + big
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class PolskieStringiTest < ActiveSupport::TestCase
|
6
|
+
test "upcase" do
|
7
|
+
assert "ąęae12EĄ.".upcase, "ĄĘAE12EĄ."
|
8
|
+
end
|
9
|
+
|
10
|
+
test "downcase" do
|
11
|
+
assert "ĄĘAE12eą.".downcase, "ąęae12eą."
|
12
|
+
end
|
13
|
+
|
14
|
+
test "cpitalize" do
|
15
|
+
assert "aDśĆv1.".capitalize, "Adśćv1."
|
16
|
+
assert "óDśĆv1.".capitalize, "Ódśćv1."
|
17
|
+
end
|
18
|
+
|
19
|
+
test "no_pl" do
|
20
|
+
assert "ĄĘAE12eąść.".downcase, "AEAE12easc."
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polskie_stringi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- v1x100r
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-18 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: v1x100r@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
files:
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README
|
32
|
+
- Rakefile
|
33
|
+
- init.rb
|
34
|
+
- lib/polskie_stringi.rb
|
35
|
+
- test/test_helper.rb
|
36
|
+
- test/polskie_stringi_test.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: ""
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: "Rozszerza funkcje klasy String o obs\xC5\x82ug\xC4\x99 polskich znak\xC3\xB3w"
|
69
|
+
test_files: []
|
70
|
+
|