Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turkish_support

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turkish_support

  • 2.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

TurkishSupport Gem Version Build Status Code Climate

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]

FAQs

Package last updated on 25 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc