TurkishSupport
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
.
Requirements
Installation
Add this line to your application's Gemfile:
gem 'turkish_support'
And then execute:
$ bundle
Or install it yourself as:
$ gem install turkish_support
Usage
After the installation of the gem, you should follow these steps.
Using with ruby
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şı', 'ç')
Using with ruby on rails
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
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
end
String Methods
<=> (spaceship)
'Cahit' <=> 'Çağla'
'Sıtkı' <=> 'Ömer'
'Eren' <=> 'Eren'
'c' <=> 'ca'
<, <=, >, >= (comparisons)
'd' > 'ç'
'aha' >= 'ağa'
'd' < 'ç'
'ağa' <= 'aha'
[] and []=
'Türkiye Cumhuriyeti'[/\w+/]
'Çetin'[/[a-ğ]+/i]
capitalize and capitalize!
str = 'türkÇE desteĞİ'
str.capitalize
str.capitalize!
casecmp
'sıtKI'.casecmp('SITkı')
downcase and downcase!
str = 'İSMAİL'
str.downcase
str.downcase!
gsub and gsub!
'ağa paşa ağa'.gsub(/\b[a-h]+\b/, 'bey')
index
'?ç-!+*/-ğüı'.index(/\w+/)
'?ç-!+*/-ğüı'.index(/[a-z]+/, 2)
match
'Aşağı'.match(/\w+/)
'Aşağı Ayrancı'.match(/^\w+\s\w+$/)
'aüvvağğ öövvaağ'.match(/^[a-z]+\s[a-z]+$/)
'BAĞCIlar'.match(/[A-Z]+/)
'Aşağı Ayrancı'.match(/\W+/)
partition
'Bağlarbaşı Çarşı'.partition(/\W+/)
rpartition
'Bağlarbaşı Çarşı Kalabalık'.rpartition(/\W+/)
rindex
'şç-!+*/-ğüı'.rindex(/\w+/, 7)
scan
'Bağlarbaşı Çarşı Kalabalık'.scan(/[a-z]+/i)
slice and slice!
'Duayen'.slice(/[^h-ö]+/)
split
'Bağlarbaşı Çarşı Kalabalık'.split(/\W+/)
'Bağlarbaşı Çarşı Kalabalık'.split(/[ç-ş]+/)
sub and sub!
'ağapaşaağa'.sub(/[a-h]+/, 'bey')
swapcase and swapcase!
'TuğÇE'.swapcase
'TuğÇE'.swapcase!
titleize and titleize!
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Ğİ'.titleize!
"rUBY roCkS... (really! 'tRUSt' ME)".titleize
upcase and upcase!
str = 'Bağcılar'
str.upcase
str
str.upcase!
str
Array Methods
sort and sort!
%w(iki üç dört ılık iğne iyne).sort
Development
To install this gem onto your local machine, run bundle exec rake install
.
Contributing
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.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the TurkishSupport project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct]