Skip to content

Commit

Permalink
feature: add String#mb_downcase method
Browse files Browse the repository at this point in the history
https://jira.railsc.ru/browse/CK-497

fix: fix mb_downcase for rails >= 4.0 and <= 4.2

rails/rails@393e19e
  • Loading branch information
Le6ow5k1 committed Nov 9, 2016
1 parent c6c1931 commit 27502f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/string_tools/core_ext/string.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf-8

require 'rchardet19'
require 'addressable/uri'
require 'active_support/core_ext/module'
Expand Down Expand Up @@ -192,6 +194,15 @@ def to_cp1251!
self.replace(self.to_cp1251)
end

def mb_downcase
# https://github.com/rails/rails/commit/393e19e508a08ede0f5037bccb984e3eb252d579
if ActiveSupport::VERSION::STRING >= '4.0.0' && ActiveSupport::VERSION::STRING <= '4.2.0'
ActiveSupport::Multibyte::Unicode.send(:database).codepoints
end

mb_chars.downcase.to_s
end

private

def surround_with_ansi(ascii_seq)
Expand Down
9 changes: 9 additions & 0 deletions spec/string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# coding: utf-8

require 'spec_helper'

describe String do
describe '#mb_downcase' do
it { expect("Кириллица".mb_downcase).to eq("кириллица") }
end
end

0 comments on commit 27502f5

Please sign in to comment.