turkish_support 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bf732fd5ed6e7e26aa61e8cc73a52ec9dcba34b
4
- data.tar.gz: a6f21e3ac420c51565ce28c2529f61ad4cf753dc
3
+ metadata.gz: cfd15f4f58e479f52c15d1a7b2e780534929305f
4
+ data.tar.gz: 6f88ae7c91ec474ab49864d1d8de5bc60549b9ab
5
5
  SHA512:
6
- metadata.gz: f3f0afc9b75f2d2f774e22a799e52b2495ba6e6d4884fd15cc7063d7921ae8c85b7eb0378894d45b494b34fe780841bf076b582ced5a12c79a4aa26e22eb403f
7
- data.tar.gz: a8885b4cff7ebdc11d7f51e745d1d257a750d7c2de0848b006e479826eb3a5647a543293dc1081ae74241281341a9213aea86692fedaa709614e88f8fa1f898a
6
+ metadata.gz: 047dfa3fc477b0aea9c1429d64d5623a886189e2e900bf51622a367a9dcc7249a967838c12082f64a93f81c69c454eae69c812a51097d58ea5ca9f0cac0dff71
7
+ data.tar.gz: ba18883f0898f891a4aa80ad13ecf7c764755fa2603a3e38efa46d91721d5ed086015394a93a5889e3e472bcc172c67ddc635b643b7d0560b8019a05082aaff8
@@ -1,13 +1,13 @@
1
1
  module TurkishSupport
2
2
  refine Array do
3
3
  def sort
4
- self.sort_by do |item|
5
- to_number_array(item)
4
+ sort_by do |item|
5
+ if item.is_a?(String)
6
+ item.chars.map { |ch| ORDERED_CHARS.index(ch) }
7
+ else
8
+ super
9
+ end
6
10
  end
7
11
  end
8
-
9
- def sort!
10
- replace(sort)
11
- end
12
12
  end
13
13
  end
@@ -1,21 +1,11 @@
1
1
  module TurkishSupport
2
- UNSUPPORTED_CHARS = {
3
- downcase: 'çğıiöşü',
4
- upcase: 'ÇĞIİÖŞÜ'
5
- }
2
+ DOWNCASED_ALPHABET = 'abcçdefgğhıijklmnoöprsştuüvyz'
3
+ UPCASED_ALPHABET = 'ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ'
6
4
 
7
- NORMALIZED_CHARS = {
8
- 'ç' => 'c',
9
- 'Ç' => 'C',
10
- 'ğ' => 'g',
11
- 'Ğ' => 'G',
12
- 'ı' => 'i',
13
- 'İ' => 'I',
14
- 'ö' => 'o',
15
- 'Ö' => 'O',
16
- 'ş' => 's',
17
- 'Ş' => 'S',
18
- 'ü' => 'u',
19
- 'Ü' => 'U'
20
- }
5
+ UNSUPPORTED_DOWNCASE_CHARS = 'çğıiöşü'
6
+ UNSUPPORTED_UPCASE_CHARS = 'ÇĞIİÖŞÜ'
7
+ ORDERED_CHARS = 'AaBbCcÇçDdEeFfGgĞğHhIıİiJjKkLlMmNnOoÖöPpQqRrSsŞşTtUuÜüVvWwXxYyZz'
8
+
9
+ DESTRUCTIVE_STRING_METHODS = %i(capitalize downcase swapcase titleize upcase)
10
+ DESTRUCTIVE_ARRAY_METHODS = %i(sort)
21
11
  end
@@ -0,0 +1,17 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ DESTRUCTIVE_STRING_METHODS.each do |method_name|
4
+ define_method "#{method_name}!" do
5
+ send(:replace, eval("#{method_name}"))
6
+ end
7
+ end
8
+ end
9
+
10
+ refine Array do
11
+ DESTRUCTIVE_ARRAY_METHODS.each do |method_name|
12
+ define_method "#{method_name}!" do
13
+ send(:replace, eval("#{method_name}"))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,9 +3,5 @@ module TurkishSupport
3
3
  def capitalize
4
4
  [chr.change_chars_for_upcase.send(:upcase), self[1..-1]].join
5
5
  end
6
-
7
- def capitalize!
8
- replace(capitalize)
9
- end
10
6
  end
11
7
  end
@@ -0,0 +1,17 @@
1
+ module TurkishSupport
2
+ refine String do
3
+ DESTRUCTIVE_STRING_METHODS.each do |method_name|
4
+ define_method "#{method_name}!" do
5
+ send(:replace, eval("#{method_name}"))
6
+ end
7
+ end
8
+ end
9
+
10
+ refine Array do
11
+ DESTRUCTIVE_ARRAY_METHODS.each do |method_name|
12
+ define_method "#{method_name}!" do
13
+ send(:replace, eval("#{method_name}"))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,9 +3,5 @@ module TurkishSupport
3
3
  def downcase
4
4
  change_chars_for_downcase.send(:downcase)
5
5
  end
6
-
7
- def downcase!
8
- replace(downcase)
9
- end
10
6
  end
11
7
  end
@@ -1,23 +1,26 @@
1
1
  module TurkishSupport
2
2
  refine String do
3
+
3
4
  def change_chars_for_upcase
4
- tr UNSUPPORTED_CHARS[:downcase], UNSUPPORTED_CHARS[:upcase]
5
+ tr UNSUPPORTED_DOWNCASE_CHARS, UNSUPPORTED_UPCASE_CHARS
5
6
  end
6
7
 
7
8
  def change_chars_for_downcase
8
- tr UNSUPPORTED_CHARS[:upcase], UNSUPPORTED_CHARS[:downcase]
9
+ tr UNSUPPORTED_UPCASE_CHARS, UNSUPPORTED_DOWNCASE_CHARS
9
10
  end
10
11
 
11
- def is_unsupported_downcase?
12
- UNSUPPORTED_CHARS[:downcase].include? chr
12
+ def unsupported_downcase?
13
+ UNSUPPORTED_DOWNCASE_CHARS.include? chr
13
14
  end
14
15
 
15
- def is_unsupported_upcase?
16
- UNSUPPORTED_CHARS[:upcase].include? chr
16
+ def unsupported_upcase?
17
+ UNSUPPORTED_UPCASE_CHARS.include? chr
17
18
  end
18
19
 
19
- def is_unsupported?
20
- is_unsupported_upcase? or is_unsupported_downcase?
20
+ def unsupported?
21
+ unsupported_upcase? or unsupported_downcase?
21
22
  end
23
+
24
+ alias_method :words, :split
22
25
  end
23
26
  end
@@ -2,16 +2,12 @@ module TurkishSupport
2
2
  refine String do
3
3
  def swapcase
4
4
  chars.map do |ch|
5
- if ch.is_unsupported?
6
- ch.is_unsupported_downcase? ? ch.upcase : ch.downcase
5
+ if ch.unsupported?
6
+ ch.unsupported_downcase? ? ch.upcase : ch.downcase
7
7
  else
8
8
  ch.send(:swapcase)
9
9
  end
10
10
  end.join
11
11
  end
12
-
13
- def swapcase!
14
- replace(swapcase)
15
- end
16
12
  end
17
13
  end
@@ -1,11 +1,7 @@
1
1
  module TurkishSupport
2
2
  refine String do
3
3
  def titleize
4
- split.map{ |w| w.downcase.capitalize }.join(' ')
5
- end
6
-
7
- def titleize!
8
- replace(titleize)
4
+ words.map { |w| w.downcase.capitalize }.join(' ')
9
5
  end
10
6
  end
11
7
  end
@@ -3,9 +3,5 @@ module TurkishSupport
3
3
  def upcase
4
4
  change_chars_for_upcase.send(:upcase)
5
5
  end
6
-
7
- def upcase!
8
- replace(upcase)
9
- end
10
6
  end
11
7
  end
@@ -1,3 +1,3 @@
1
1
  module TurkishSupport
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -9,8 +9,9 @@ require "turkish_support/string/titleize"
9
9
  require "turkish_support/string/casecmp"
10
10
  require "turkish_support/string/swapcase"
11
11
 
12
- require "turkish_support/array/helpers"
13
12
  require "turkish_support/array/sort"
14
13
 
14
+ require "turkish_support/destructives"
15
+
15
16
  module TurkishSupport
16
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turkish_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sıtkı Bağdat
@@ -68,11 +68,12 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/turkish_support.rb
71
- - lib/turkish_support/array/helpers.rb
72
71
  - lib/turkish_support/array/sort.rb
73
72
  - lib/turkish_support/constants.rb
73
+ - lib/turkish_support/destructives.rb
74
74
  - lib/turkish_support/string/capitalize.rb
75
75
  - lib/turkish_support/string/casecmp.rb
76
+ - lib/turkish_support/string/destructives.rb
76
77
  - lib/turkish_support/string/downcase.rb
77
78
  - lib/turkish_support/string/helpers.rb
78
79
  - lib/turkish_support/string/swapcase.rb
@@ -1,17 +0,0 @@
1
- module TurkishSupport
2
- refine Array do
3
- def to_number_array(string)
4
- string.split('').map{|c| integer_order(c) }
5
- end
6
-
7
- def integer_order(char)
8
- if char.match(/[ı]/)
9
- NORMALIZED_CHARS[char].ord - 0.5
10
- elsif char.match(/[çÇğĞİöÖşŞüÜ]/)
11
- NORMALIZED_CHARS[char].ord + 0.5
12
- else
13
- char.ord
14
- end
15
- end
16
- end
17
- end