chupakabra_tools 0.0.5 → 0.0.7
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/chupakabra_tools.gemspec
CHANGED
data/lib/chupakabra_tools.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "russian"
|
2
|
+
|
3
|
+
class ChupakabraTools::Transliterator
|
4
|
+
|
5
|
+
def self.translify(str)
|
6
|
+
str = str.to_s unless str.is_a?(String)
|
7
|
+
Russian.transliterate(str)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.dirify(str)
|
11
|
+
result_str = translify(str)
|
12
|
+
result_str.gsub!(/(\s\&\s)|(\s\&\;\s)/, ' and ') # convert & to "and"
|
13
|
+
result_str.gsub!(/\W/, ' ') #replace non-chars
|
14
|
+
result_str.gsub!(/(_)$/, '') #trailing underscores
|
15
|
+
result_str.gsub!(/^(_)/, '') #leading unders
|
16
|
+
result_str.strip.gsub(/(\s)/,'-').downcase.squeeze('-')
|
17
|
+
end
|
18
|
+
end
|
@@ -7,4 +7,74 @@ module ChupakabraTools::Validations
|
|
7
7
|
def russian_letters_and_digits
|
8
8
|
/^[а-яА-Я0-9\ ,;.\-]+$/
|
9
9
|
end
|
10
|
+
|
11
|
+
|
12
|
+
def phone(phone, params={})
|
13
|
+
|
14
|
+
params ||= {}
|
15
|
+
|
16
|
+
|
17
|
+
if phone.nil?
|
18
|
+
return params[:allow_nil] && params[:allow_nil] == true
|
19
|
+
end
|
20
|
+
|
21
|
+
unless phone.is_a?(String)
|
22
|
+
phone = phone.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
phone.strip!
|
26
|
+
|
27
|
+
if phone.blank?
|
28
|
+
return params[:allow_blank] && params[:allow_blank] == true
|
29
|
+
end
|
30
|
+
|
31
|
+
phone = phone.gsub(/[^0-9]/, "")
|
32
|
+
|
33
|
+
# checking phone lengths for each country
|
34
|
+
if phone.starts_with?("7")
|
35
|
+
# for Russia, Kazahstan, Abhazia and so on
|
36
|
+
phone = phone.length == 11 ? phone : nil
|
37
|
+
#phone += " Russia" if phone
|
38
|
+
elsif phone.starts_with?("38")
|
39
|
+
# Ukrine
|
40
|
+
phone = phone.length == 12 ? phone : nil
|
41
|
+
#phone += " Ukraine" if phone
|
42
|
+
elsif phone.starts_with?("375")
|
43
|
+
# Belarus
|
44
|
+
phone = phone.length == 12 ? phone : nil
|
45
|
+
#phone += " Belarus" if phone
|
46
|
+
elsif phone.starts_with?("370")
|
47
|
+
# Litua
|
48
|
+
phone = phone.length == 11 ? phone : nil
|
49
|
+
#phone += " Litva" if phone
|
50
|
+
elsif phone.starts_with?("371")
|
51
|
+
# Latvia
|
52
|
+
phone = phone.length == 11 ? phone : nil
|
53
|
+
#phone += " Latvia" if phone
|
54
|
+
elsif phone.starts_with?("372")
|
55
|
+
# Estonia
|
56
|
+
phone = phone.length == 11 || phone.length == 10 ? phone : nil
|
57
|
+
#phone += " Estonia" if phone
|
58
|
+
elsif phone.starts_with?("995") && phone.length != 12
|
59
|
+
# Geogia
|
60
|
+
phone = phone.length == 11 ? phone : nil
|
61
|
+
#phone += " Georgia" if phone
|
62
|
+
elsif phone.starts_with?("374")
|
63
|
+
#Armenia
|
64
|
+
phone = phone.length == 11 ? phone : nil
|
65
|
+
#phone += " Armenia" if phone
|
66
|
+
elsif phone.starts_with?("994")
|
67
|
+
# Azerbadzhan
|
68
|
+
phone = phone.length == 12 ? phone : nil
|
69
|
+
#phone += " Azerbaidzhan" if phone
|
70
|
+
elsif phone.starts_with?("373")
|
71
|
+
# Moldova
|
72
|
+
phone = phone.length == 11 ? phone : nil
|
73
|
+
#phone += " Moldova" if phone
|
74
|
+
else
|
75
|
+
phone = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
phone ? true : false
|
79
|
+
end
|
10
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chupakabra_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: russian
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: Chupakbara Tools Set for Easy Life
|
63
79
|
email:
|
64
80
|
- mdima@it-guru.biz
|
@@ -80,6 +96,7 @@ files:
|
|
80
96
|
- lib/chupakabra_tools/predefined_time_intervals.rb
|
81
97
|
- lib/chupakabra_tools/security.rb
|
82
98
|
- lib/chupakabra_tools/time_interval.rb
|
99
|
+
- lib/chupakabra_tools/transliterator.rb
|
83
100
|
- lib/chupakabra_tools/validattions.rb
|
84
101
|
- lib/chupakabra_tools/version.rb
|
85
102
|
homepage: ''
|