TurkishSupport

Gem Version Build Status

Turkish character support for some core ruby methods. This gem provide support for these methods: String#upcase, String#downcase, String#capitalize, String#swapcase, String#casecmp, String#match, Array#sort, Array#sort!, and their destructive versions like String#capitalize!. It also gives you some bonus methods like String#titleize.

Requirements

  • Ruby >= 2.0.0
  • Rails >= 4.0.0

Notice: TurkishSupport uses refinements instead of monkey patching. Refinements come with Ruby 2.0.0 as a new feature and also, it is an experimental feature for now. If you want to more information about refinements, you can see the doc at http://www.ruby-doc.org/core-2.0.0/doc/syntax/refinements_rdoc.html

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 Instructions

After the installation of the gem, you should follow these steps.

Using with ruby

  • Require the gem:
  require TurkishSupport
  • Add using TurkishSupport line to where you want to activate it.
  using TurkishSupport

Example usage on the terminal:

$ require 'turkish_support'     #=> true
$ using TurkishSupport          #=> main
$ 'içel'.upcase                 #=> "İÇEL"

Example usage inside a class:

require 'turkish_support'

class Test
  using TurkishSupport
  def up_me(str)
    str.upcase
  end
end

Test.new.up_me('içel')  #=> "İÇEL"

Using with rails

Note: You don't need to require, because it is already required by the rails.

  • In rails you must add using TurkishSupport line to the top of the scope, not inside of any class or module.
  using TurkishSupport

  class SampleModel
    ...
  end

Examples

Within the file that you added using TurkishSupport line; you can use the core methods like below:

String#upcase and String#upcase!

  str = 'Bağcılar'

  str.upcase    #=> "BAĞCILAR"
  str           #=> "Bağcılar"

  str.upcase!   #=> "BAĞCILAR"
  str           #=> "BAĞCILAR"

String#downcase and String#downcase!

  str = 'İSMAİL'
  str.downcase    #=> "ismail"

String#capitalize and String#capitalize!

  str = 'türkÇE desteĞİ'
  str.capitalize    #=> "Türkçe desteği"

String#swapcase and String#swapcase!

  'TuğÇE'.swapcase    #=> "tUĞçe"

String#casecmp

  'sıtKI'.casecmp('SITkı')     #=> 0

String#match

  '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 "">

Array#sort and Array#sort!

  %w(iki üç dört ılık iğne iyne).sort
  #=> ["dört", "ılık", "iğne", "iki", "iyne", "üç"]

String#titleize and String#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ği"

  # Parenthesis, quotes, etc. support
  "rUBY roCkS... (really! 'tRUSt' ME)".titleize          #=> "Ruby Rocks... (Really! 'Trust' Me)"

  # If you don't want to capitalize conjuctions, simply pass a false value as a parameter
  "kerem VE aslı VeYa leyla İlE mecnun".titleize(false)  #=> "Kerem ve Aslı veya Leyla ile Mecnun"

Important Note: If you also want to use original set of the core methods in the same scope, you can use send method like this:

  str = 'Bağcılar'
  str.send(:upcase)  #=> "BAğCıLAR"

Contributing

  1. Fork it ( http://github.com/sbagdat/turkish_support/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request