Turkish character support for core ruby methods. This gem provides support nearly all String
methods,
such as String#split
, String#match
, String#gsub
. It also provides support for Array#sort
and some
bonus methods like String#titleize
.
-
Ruby >= 2.7.0
-
Rails >= 6.0.0
Add this line to your application's Gemfile:
gem 'turkish_support'
And then execute:
$ bundle
Or install it yourself as:
$ gem install turkish_support
After the installation of the gem, you should follow these steps.
- Require the gem:
require 'turkish_support'
- Add
using TurkishSupport
line to a class or a module.
Example usage inside a class:
require 'turkish_support'
class CanSpeakInTurkish
using TurkishSupport
def split_me_up(string, sep)
string.split(sep)
end
end
CanSpeakInTurkish.new.split_me_up('çarçarıçarşı', 'ç')
# ['ar', 'arı', 'arşı']
Note: You don't need to require, because it is already required by the rails.
- You must add
using TurkishSupport
line to the top of the scope.
using TurkishSupport
class TopModel < ApplicationRecord
# your code goes here
end
- If you want to use TurkishSupport with a custom class or a module that is not inherited from any rails tie,
you must add
using TurkishSupport
line to the class or module.
class CustomClass
using TurkishSupport
# your code goes here
end
'Cahit' <=> 'Çağla' # => -1
'Sıtkı' <=> 'Ömer' # => 1
'Eren' <=> 'Eren' # => 0
'c' <=> 'ca' # => -1
'd' > 'ç' # => true
'aha' >= 'ağa' # => true
'd' < 'ç' # => false
'ağa' <= 'aha' # => true
'Türkiye Cumhuriyeti'[/\w+/] # => "Türkiye"
'Çetin'[/[a-ğ]+/i] # => "Çe"
str = 'türkÇE desteĞİ'
str.capitalize # => "Türkçe desteği"
str.capitalize! # => "Türkçe desteği"
'sıtKI'.casecmp('SITkı') # => 0
str = 'İSMAİL'
str.downcase # => "ismail"
str.downcase! # => "ismail"
'ağa paşa ağa'.gsub(/\b[a-h]+\b/, 'bey') # => "bey paşa bey"
'?ç-!+*/-ğüı'.index(/\w+/) # => 1
'?ç-!+*/-ğüı'.index(/[a-z]+/, 2) # => 8
'Aşağı'.match(/\w+/)
# => #<MatchData "Aşağı">
'Aşağı Ayrancı'.match(/^\w+\s\w+$/)
# => #<MatchData "Aşağı Ayrancı">
'aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/)
# => #<MatchData "aüvvağğ öövvaağ">
'BAĞCIlar'.match(/[A-Z]+/)
# => #<MatchData "BAĞCI">
'Aşağı Ayrancı'.match(/\W+/)
# => #<MatchData "">
'Bağlarbaşı Çarşı'.partition(/\W+/) # => ["Bağlarbaşı", " ", "Çarşı"]
'Bağlarbaşı Çarşı Kalabalık'.rpartition(/\W+/)
# => ["Bağlarbaşı Çarşı", " ", "Kalabalık"]
'şç-!+*/-ğüı'.rindex(/\w+/, 7) # => 1
'Bağlarbaşı Çarşı Kalabalık'.scan(/[a-z]+/i)
# => ["Bağlarbaşı", "Çarşı", "Kalabalık"]
'Duayen'.slice(/[^h-ö]+/) # => "Duaye"
'Bağlarbaşı Çarşı Kalabalık'.split(/\W+/)
# => ["Bağlarbaşı", "Çarşı", "Kalabalık"]
'Bağlarbaşı Çarşı Kalabalık'.split(/[ç-ş]+/)
# => ["Ba", "a", "ba", " Ça", " Ka", "aba"]
'ağapaşaağa'.sub(/[a-h]+/, 'bey') # => "beypaşaağa"
'TuğÇE'.swapcase # => "tUĞçe"
'TuğÇE'.swapcase! # => "tUĞçe"
These methods are not core methods of ruby, but they are accepted as useful in most situations.
'türkÇE desteĞİ'.titleize # => "Türkçe Desteği"
'türkÇE desteĞİ'.titleize! # => "Türkçe Desteği"
# Parenthesis, quotes, etc. support
"rUBY roCkS... (really! 'tRUSt' ME)".titleize
# => "Ruby Rocks... (Really! 'Trust' Me)"
str = 'Bağcılar'
str.upcase # => "BAĞCILAR"
str # => "Bağcılar"
str.upcase! # => "BAĞCILAR"
str # => "BAĞCILAR"
%w(iki üç dört ılık iğne iyne).sort
# => ["dört", "ılık", "iğne", "iki", "iyne", "üç"]
To install this gem onto your local machine, run bundle exec rake install
.
Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/turkish_support. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the TurkishSupport project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct]