Module: Myasorubka::Unicode

Extended by:
Unicode
Included in:
Unicode
Defined in:
lib/myasorubka/unicode.rb

Overview

This module provides downcase and upcase methods designed for Russian. The original code is written by Andrew Kozlov for the Petrovich library.

github.com/petrovich/petrovich-ruby/blob/df705075542979ab85e1f2bf9a2024b1c0813e1a/lib/petrovich/unicode.rb

Constant Summary collapse

RU_UPPERCASE =

Russian capital letters.

[
  "\u0410", "\u0411", "\u0412", "\u0413", "\u0414", "\u0415", "\u0416", "\u0417",
  "\u0418", "\u0419", "\u041A", "\u041B", "\u041C", "\u041D", "\u041E", "\u041F",
  "\u0420", "\u0421", "\u0422", "\u0423", "\u0424", "\u0425", "\u0426", "\u0427",
  "\u0428", "\u0429", "\u042A", "\u042B", "\u042C", "\u042D", "\u042E", "\u042F",
  "\u0401" # Ё
].join
RU_LOWERCASE =

Russian small letters.

[
  "\u0430", "\u0431", "\u0432", "\u0433", "\u0434", "\u0435", "\u0436", "\u0437",
  "\u0438", "\u0439", "\u043A", "\u043B", "\u043C", "\u043D", "\u043E", "\u043F",
  "\u0440", "\u0441", "\u0442", "\u0443", "\u0444", "\u0445", "\u0446", "\u0447",
  "\u0448", "\u0449", "\u044A", "\u044B", "\u044C", "\u044D", "\u044E", "\u044F",
  "\u0451" # Ё
].join

Instance Method Summary collapse

Instance Method Details

#downcase(string) ⇒ String

Returns a copy of the given string having replaced capital Russian letters with small ones.

Parameters:

  • string (String)

    a string.

Returns:

  • (String)

    a new string.



33
34
35
# File 'lib/myasorubka/unicode.rb', line 33

def downcase(string)
  string.tr(RU_UPPERCASE, RU_LOWERCASE).tap(&:downcase!)
end

#upcase(string) ⇒ String

Returns a copy of the given string having replaced small Russian letters with capital ones.

Parameters:

  • string (String)

    a string.

Returns:

  • (String)

    a new string.



43
44
45
# File 'lib/myasorubka/unicode.rb', line 43

def upcase(string)
  string.tr(RU_LOWERCASE, RU_UPPERCASE).tap(&:upcase!)
end