Git Product home page Git Product logo

turkish_support's Introduction

TurkishSupport

Gem Version Build Status Code Climate Coverage Status

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#sortand 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 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şı']

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
    # 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

String Methods

<=> (spaceship)

  'Cahit' <=> 'Çağla' # => -1
  'Sıtkı' <=> 'Ömer'  # =>  1
  'Eren'  <=> 'Eren'  # =>  0
  'c'     <=> 'ca'    # => -1

<, <=, >, >= (comparisons)

  'd'   >  'ç'     # => true
  'aha' >= 'ağa'   # => true
  'd'   <  'ç'     # => false
  'ağa' <= 'aha'   # => true

[] and []=

  'Türkiye Cumhuriyeti'[/\w+/] # => "Türkiye"
  'Çetin'[/[a-ğ]+/i]           # => "Çe"

capitalize and capitalize!

  str = 'türkÇE desteĞİ'

  str.capitalize    # => "Türkçe desteği"
  str.capitalize!   # => "Türkçe desteği"

casecmp

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

downcase and downcase!

  str = 'İSMAİL'

  str.downcase    # => "ismail"
  str.downcase!   # => "ismail"

gsub and gsub!

  'ağa paşa ağa'.gsub(/\b[a-h]+\b/, 'bey') # => "bey paşa bey"

index

  '?ç-!+*/-ğüı'.index(/\w+/)        # => 1
  '?ç-!+*/-ğüı'.index(/[a-z]+/, 2)  # => 8

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

partition

  'Bağlarbaşı Çarşı'.partition(/\W+/) # => ["Bağlarbaşı", " ", "Çarşı"]

rpartition

  'Bağlarbaşı Çarşı Kalabalık'.rpartition(/\W+/)
  # => ["Bağlarbaşı Çarşı", " ", "Kalabalık"]

rindex

  'şç-!+*/-ğüı'.rindex(/\w+/, 7)  # => 1

scan

  'Bağlarbaşı Çarşı Kalabalık'.scan(/[a-z]+/i)
  # => ["Bağlarbaşı", "Çarşı", "Kalabalık"]

slice and slice!

  'Duayen'.slice(/[^h-ö]+/) # => "Duaye"

split

  'Bağlarbaşı Çarşı Kalabalık'.split(/\W+/)
  # => ["Bağlarbaşı", "Çarşı", "Kalabalık"]

  'Bağlarbaşı Çarşı Kalabalık'.split(/[ç-ş]+/)
  # => ["Ba", "a", "ba", " Ça", " Ka", "aba"]

sub and sub!

  'ağapaşaağa'.sub(/[a-h]+/, 'bey')  # => "beypaşaağa"

swapcase and swapcase!

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

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ğ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)"

upcase and upcase!

  str = 'Bağcılar'

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

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

Array Methods

sort and sort!

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

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]

turkish_support's People

Contributors

dependabot-preview[bot] avatar furkanayhan avatar sbagdat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

turkish_support's Issues

# frozen_string_literal: true hatası

Sayfanın başına # frozen_string_literal: true magic comment ekledikten sonra upcase ve downcase string fonksiyonlarında can't define singleton gibi bir hata alıyorum.

Usage inside irb

Add usage in irb to README for testing functionality of the gem.

iterasyonlarda shorthand notasyonunda hatali sonuc (&:)

Selam,
Mesela row.map {|elem| elem.capitalize} yerine row.map(&:capitalize) yazinca Turkce destegi calismiyor. Ornek:

row = ["NEVŞEHİR", "ACIGÖL", "MERKEZKÖYLER", "1 KÜME MAH (AĞILLI KÖYÜ)", "50142"]

row.map {|elem| elem.capitalize} => ["Nevşehir", "Acıgöl", "Merkezköyler", "1 küme mah (ağıllı köyü)", "50142"]

row.map(&:capitalize) => ["NevŞehİr", "AcigÖl", "MerkezkÖyler", "1 kÜme mah (aĞilli kÖyÜ)", "50142"]

Sanirim ikincisinde Proc objesi yarattigi icin oluyor

comparison of Array with Array failed (ArgumentError)

önce hata çıktısı

.rvm/gems/ruby-2.3.3@rails5_1_1/gems/turkish_support-1.0.3/lib/turkish_support/array_methods.rb:4:in sort_by': comparison of Array with Array failed (ArgumentError)`

.rvm/gems/ruby-2.3.3@rails5_1_1/gems/turkish_support-1.0.3/lib/turkish_support/array_methods.rb:4:in sort'
from ./sort.rb:13:in <main>'

bu hatayı içinde türkçe karakter olmayan dizinlerde de alıyorum

# şu sorunsuz çalışıyor
['isim soyisim', 'isim soyisim'].sort

# şu ise çalışmıyor
['isim soyisim', 'isim1 soyisim'].sort

# aynı şekilde bu da çalışmıyor
['isim1 soyisim', 'isim soyisim'].sort

sorun sadece boşluk olmasında da değil

# bu çalışıyor
['isim1soyisim', 'isim2soyisim'].sort

# bunlar ise çalışmıyor
['isim1soyisim', 'isim21soyisim'].sort
['1soyisim', '12soyisim'].sort
['a', '3s'].sort
['1a', 'b'].sort
['a', '2 b'].sort

# her kelimeden sonra birer boşluk var
['a ' , 'ab '].sort

upcase problem

Hey,
There is a problem with "i" character when upcasing it.

str = "içel"
str.upcase
str        #=> "IÇEL"

It should be "İÇEL".

Stack level too deep error for string_methods

I am trying to comparison strings with usign Ruby upcase method. For example;

banks.select { |b| b["banka"]["bAd"] == bank_name.upcase }

Here when I try to run rspec tests I faced SystemStackError: stack level too deep error. It occurs on

../ruby-2.6.2/gems/turkish_support-1.1.3/lib/turkish_support/string_methods.rb:18

Could you help me?

Cheers.

Problem with opening parentheses

'LOREM ( IPSUM)'.titleize
/Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/helpers.rb:28:in `prepare_for': Invalid arguments for method `prepare_for`! (ArgumentError)
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/helpers.rb:67:in `prepare_for_capitalize'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/helpers.rb:31:in `call'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/helpers.rb:31:in `prepare_for'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/string_methods.rb:19:in `block (3 levels) in <module:TurkishSupport>'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/string_methods.rb:30:in `block in titleize'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/string_methods.rb:25:in `map'
    from /Users/halil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/turkish_support-1.0.0/lib/turkish_support/string_methods.rb:25:in `titleize'
    from test.rb:9:in `hey'
    from test.rb:13:in `<main>'
'( '.titleize # => <The same error>
'('.titleize # => <The same error>
'LOREM (IPSUM)'.titleize # => Lorem (Ipsum)

<=> operator

Hi i'm trying to use sort method with <=> operator

.sort { |a,b| a[0] <=> b[0] }

but didn't work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.