Skip to content

Commit

Permalink
added downcase method that understands Serbian Cyrillic
Browse files Browse the repository at this point in the history
-version bump
-renamed the call to Cucumber

NOTE: the downcase method might be slower now as it uses Ruby's Array
to look up the characters for the conversion.
  • Loading branch information
dotemacs committed Feb 18, 2012
1 parent c85e4ed commit 041f75c
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 8 deletions.
23 changes: 22 additions & 1 deletion README.md
Expand Up @@ -3,6 +3,8 @@
Character conversion from Latin alphabet to Serbian Cyrillic script
and vice versa

It adds **downcase** method that understands Serbian Cyrillic case


### Install

Expand All @@ -14,13 +16,32 @@ $ gem install viljushka

```
require 'viljushka'
```

For Cyrillic


```
puts 'ćirilica'.to_cyr
puts 'ćirilica'.po_vuku
``
and for Latin
``
puts 'латиница'.to_lat
puts 'латиница'.po_gaju
```

Also added **downcase**

```
puts 'ПАЗИ САД'.downcase
=> "пази сад"
```

### Note

The idea for this gem comes from Dalibor Nasevic, who originally
created it for Macedonian Cyrillic
created it for Macedonian Cyrillic. I have since modified it by
adding **downcase** method
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -8,6 +8,6 @@ task :default => :spec
desc "Run specs"
RSpec::Core::RakeTask.new

Cucumber::Rake::Task.new(:features) do |t|
Cucumber::Rake::Task.new(:cukes) do |t|
t.cucumber_opts = "features --format pretty"
end
39 changes: 39 additions & 0 deletions features/downcase.feature
@@ -0,0 +1,39 @@
Feature: Convert from uppercase To lowercase
In order to convert text from uppercase to lowercase

Scenario Outline: User enters Latin characters
When I enter a <Uppercase> character
Then I should get it in <Lowercase>

Examples:
| Uppercase | Lowercase |
| А | а |
| Б | б |
| В | в |
| Г | г |
| Д | д |
| Ђ | ђ |
| Е | е |
| Ж | ж |
| З | з |
| И | и |
| Ј | ј |
| К | к |
| Л | л |
| Љ | љ |
| М | м |
| Н | н |
| Њ | њ |
| О | о |
| П | п |
| Р | р |
| С | с |
| Т | т |
| Ћ | ћ |
| У | у |
| Ф | ф |
| Х | х |
| Ц | ц |
| Ч | ч |
| Џ | џ |
| Ш | ш |
7 changes: 7 additions & 0 deletions features/step_definitions/downcase_steps.rb
@@ -0,0 +1,7 @@
When /^I enter a (.*) character$/ do |char|
@char = char
end

Then /^I should get it in (.*)$/ do |lowercase|
@char.downcase.should == lowercase
end
3 changes: 2 additions & 1 deletion features/support/env.rb
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + "/../../lib/viljushka"
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)

require 'cucumber'
require 'rspec'
require 'viljushka'
1 change: 1 addition & 0 deletions lib/viljushka.rb
@@ -1 +1,2 @@
require 'viljushka/boc'
require 'viljushka/downcase'
5 changes: 1 addition & 4 deletions lib/viljushka/boc.rb
Expand Up @@ -2,11 +2,8 @@
module Viljushka
module Boc

# Including officially 'non valid' (read: used on the internet, by
# people who can't be bothered to set up their keyboard layouts)
# Serbian Latin characters as well as the official letters
Latin = %w(DJ Dj dj LJ Lj lj NJ Nj nj A a B b V v G g D d Đ đ Ð ð E e Ž ž Z z I i J j K k L l M m N n O o P p R r S s T t Ć ć U u F f H h C c Č č Š š)
Cyrillic = %w(Ђ Ђ ђ Џ Џ џ Љ Љ љ Њ Њ њ А а Б б В в Г г Д д Ђ ђ Ђ ђ Е е Ж ж З з И и Ј ј К к Л л М м Н н О о П п Р р С с Т т Ћ ћ У у Ф ф Х х Ц ц Ч ч Ш ш)
Cyrillic = %w(Ђ Ђ ђ Џ Џ џ Љ Љ љ Њ Њ њ А а Б б В в Г г Д д Ђ ђ Ђ ђ Е е Ж ж З з И и Ј ј К к Л л М м Н н О о П п Р р С с Т т Ћ ћ У у Ф ф Х х Ц ц Ч ч Ш ш)

def to_cyr
convert(self.dup, Latin, Cyrillic)
Expand Down
29 changes: 29 additions & 0 deletions lib/viljushka/downcase.rb
@@ -0,0 +1,29 @@
# coding: utf-8
module Viljushka
module Downcase

Up = %w(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z А Б В Г Д Ђ Е Ж З И Ј К Л Љ М Н Њ О П Р С Т Ћ У Ф Х Ц Ч Џ Ш)
Low = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z а б в г д ђ е ж з и ј к л љ м н њ о п р с т ћ у ф х ц ч џ ш)

def downcase_with_serbian_cyrillic
convert(self.dup, Up, Low)
end

alias_method :downcase, :downcase_with_serbian_cyrillic

private

def convert(text, from, to)
from.each_with_index do |char, i|
text.gsub!(char, to[i])
end
text
end

end
end

class String
remove_method(:downcase)
include Viljushka::Downcase
end
2 changes: 1 addition & 1 deletion lib/viljushka/version.rb
@@ -1,3 +1,3 @@
module Viljushka
VERSION = '0.1.5'
VERSION = '0.2.0'
end
16 changes: 16 additions & 0 deletions spec/downcase_spec.rb
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
require 'spec_helper'

describe "Viljushka::Downcase" do

context "with alphabet" do
subject { "ABCDEFGHIJKLMNOPQRSTUVWXYZ".downcase }
it { should eql "abcdefghijklmnopqrstuvwxyz" }
end

context "with Serbian Cyrillic" do
subject { "АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ".downcase }
it { should eql "абвгдђежзијклљмнњопрстћуфхцчџш" }
end

end

0 comments on commit 041f75c

Please sign in to comment.