uaenv 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -46,9 +46,13 @@ UaEnv реалізує суму прописом для цілих і дробо
46
46
  puts "#{Date::UA_DAYNAMES[date.wday]}" => п'ятниця
47
47
 
48
48
  Відбувається "перекриття" стандартної
49
- функції Time#strftime ("рідну" #strftime можно продовжити використовуватичерез alias-метод #strftime_nouaenv):
49
+ функції Time#strftime ("рідну" #strftime можно продовжити використовувати через alias-метод #strftime_nouaenv):
50
50
 
51
51
  Time.local(2007,"jan",5).strftime("%a, %A, %b, %B") => "пт, п'ятниця, січ, січень"
52
52
  Time.local(2007,"jan",5).strftime_nouaenv("%a, %A, %b, %B") => "Fri, Friday, Jan, January"
53
+ Time.now.strftime("Сьогодні %A, %d %B %Y року, %H:%M:%S") => "Сьогодні субота, 6 січня 2007 року, 14:50:34"
53
54
 
55
+ == Транслітерація
54
56
 
57
+ Транслітерація української кирилиці у латиницю:
58
+ "Привіт, як справи?".translify >> "Pryvit, yak spravy?"
@@ -20,7 +20,7 @@ end # module UaEnv
20
20
 
21
21
  class Date
22
22
  UA_MONTHNAMES = [nil] + %w{ січень лютий березень квітень травень червень липень серпень вересень жовтень листопад грудень }
23
- UA_DAYNAMES = %w(неділя понеділок вівторок середа черверг п'ятниця субота)
23
+ UA_DAYNAMES = %w(неділя понеділок вівторок середа червер п'ятниця субота)
24
24
  UA_ABBR_MONTHNAMES = [nil] + %w{ січ лют бер кві тра чер лип сер вер жов лис гру }
25
25
  UA_ABBR_DAYNAMES = %w(нд пн вт ср чт пт сб)
26
26
  UA_INFLECTED_MONTHNAMES = [nil] + %w{ січня лютого березня квітня травня червня липня серпня вересня жовтня листопада грудня }
@@ -0,0 +1,65 @@
1
+ #
2
+ # ** Notes for the Ukrainian National system
3
+ # Transliteration can be rendered in a simplified form:
4
+ # 1. Doubled consonants ж, х, ц, ч, ш are simplified, for example Запоріжжя Zaporizhia.
5
+ # 2. Apostrophe and soft sign are omitted, except for ьо and ьї which are always rendered as ’o and ’i.
6
+ # 3. gh is used in the romanization of зг (zgh), avoiding confusion with ж (zh).
7
+ # 4. The second variant is used at the beginning of a word.
8
+
9
+
10
+ module UaEnv::Transliteration::National
11
+
12
+ UA_UPPER = %w{ А Б В Г Ґ Д Е Є Ж З И І Ї Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ю Я Ь ' }
13
+ UA_LOWER = %w{ а б в г ґ д е є ж з и і ї й к л м н о п р с т у ф х ц ч ш щ ю я ь ' }
14
+
15
+ UA = UA_LOWER + UA_UPPER
16
+
17
+ NATIONAL_LOWER = ['a', 'b', 'v', ['h', 'gh'], 'g', 'd',
18
+ 'e', ['ie','ye'], 'zh', 'z', 'y', 'i',
19
+ ['i','yi'], ['i','y'], 'k', 'l', 'm', 'n',
20
+ 'o', 'p', 'r', 's', 't', 'u',
21
+ 'f', 'kh', 'ts', 'ch', 'sh', 'sch',
22
+ ['iu','yu'], ['ia','ya'], '\'', '"'
23
+ ]
24
+
25
+ NATIONAL_UPPER = NATIONAL_LOWER.map{ |i| i.is_a?( Array ) ? i.map{ |j| j.upcase } : i.upcase }
26
+
27
+ NATIONAL = NATIONAL_LOWER + NATIONAL_UPPER
28
+
29
+ TABLE = {}
30
+ UA.each_with_index {|char,index| TABLE[char] = NATIONAL[index]}
31
+
32
+
33
+ # Просто замінює кирилицю в строці на латиницю
34
+ def self.translify(str)
35
+ chars = str.split(//)
36
+
37
+ result = ''
38
+ chars.each_with_index do | char, index |
39
+ variant = (index != 0 ? ( chars[index - 1] == " " ? 1 : 0 ) : 1)
40
+ if UA_UPPER.include?(char) && UA_LOWER.include?(chars[index+1])
41
+ # "Яна" => "Yana"
42
+ ch = (TABLE[char].is_a?(Array) ? TABLE[char][variant].downcase.capitalize : TABLE[char].downcase.capitalize)
43
+ result << ch
44
+
45
+ elsif UA_UPPER.include?(char)
46
+ # "ЯНА" => "YANA"
47
+ ch = (TABLE[char].is_a?(Array) ? TABLE[char][variant] : TABLE[char] )
48
+ result << ch
49
+
50
+ elsif UA_LOWER.include?(char)
51
+ # "яна" => "yana"
52
+ ch = (TABLE[char].is_a?(Array) ? TABLE[char][variant] : TABLE[char] )
53
+ result << ch
54
+
55
+ else
56
+ result << char
57
+ end
58
+
59
+ end
60
+ return result
61
+
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,28 @@
1
+ # See also:
2
+ # http://en.wikipedia.org/wiki/Romanization_of_Ukrainian
3
+ # http://uk.wikipedia.org/wiki/Транслітерація_української_мови_латиницею
4
+ # http://www.sdip.gov.ua/ukr/laws/3267/?print=yes
5
+
6
+ module UaEnv
7
+ module Transliteration #:nodoc:
8
+ end
9
+ end
10
+
11
+ require File.join(File.dirname(__FILE__), 'national')
12
+
13
+ # Реалізує транслітерацію будь-якого об'єкта, що реалізує String
14
+ module UaEnv::Transliteration::StringFormatting
15
+
16
+ #Транслітерація строки у латиницю
17
+ def translify
18
+ UaEnv::Transliteration::National::translify(self.to_s)
19
+ end
20
+
21
+ def translify!
22
+ self.replace(self.translify)
23
+ end
24
+ end
25
+
26
+ class Object::String
27
+ include UaEnv::Transliteration::StringFormatting
28
+ end
@@ -5,7 +5,7 @@ module UaEnv
5
5
  INSTALLATION_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../') #:nodoc:
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- TINY = 1
8
+ TINY = 3
9
9
 
10
10
  # Версія UaEnv
11
11
  VERSION = [MAJOR, MINOR ,TINY].join('.') #:nodoc:
@@ -24,3 +24,4 @@ end
24
24
 
25
25
  UaEnv::load_component :datetime # Дата і час без локалі
26
26
  UaEnv::load_component :pluralizer #Вивід чисел прописом
27
+ UaEnv::load_component :transliteration # Транслітерація
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: uaenv
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-01-06 00:00:00 +02:00
8
- summary: Simply procesing Ukrainian text
6
+ version: 0.0.3
7
+ date: 2007-01-17 00:00:00 +02:00
8
+ summary: Simple processing of Ukrainian strings
9
9
  require_paths:
10
10
  - lib
11
11
  email: anton.linux @nospam@ google.com
12
- homepage:
13
- rubyforge_project:
12
+ homepage: http://rubyforge.org/projects/uaenv
13
+ rubyforge_project: uaenv
14
14
  description:
15
15
  autorequire: uaenv
16
16
  default_executable:
@@ -32,6 +32,8 @@ files:
32
32
  - lib/uaenv.rb
33
33
  - lib/datetime/datetime.rb
34
34
  - lib/pluralizer/pluralizer.rb
35
+ - lib/transliteration/transliteration.rb
36
+ - lib/transliteration/national.rb
35
37
  - README
36
38
  test_files: []
37
39