chupakabra_tools 0.0.20 → 0.0.22
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.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.idea/chupakabra_tools.iml +18 -9
- data/.idea/workspace.xml +191 -152
- data/Gemfile.lock +21 -26
- data/chupakabra_tools.gemspec +2 -2
- data/lib/.DS_Store +0 -0
- data/lib/chupakabra_tools.rb +7 -21
- data/lib/chupakabra_tools/.DS_Store +0 -0
- data/lib/chupakabra_tools/active_record.rb +54 -52
- data/lib/chupakabra_tools/class_helper.rb +256 -231
- data/lib/chupakabra_tools/convert.rb +62 -62
- data/lib/chupakabra_tools/http.rb +19 -17
- data/lib/chupakabra_tools/number_as_text.rb +48 -46
- data/lib/chupakabra_tools/security.rb +90 -51
- data/lib/chupakabra_tools/strings.rb +34 -37
- data/lib/chupakabra_tools/transliterator.rb +15 -13
- data/lib/chupakabra_tools/validations.rb +75 -73
- data/lib/chupakabra_tools/xml_parser.rb +52 -0
- data/lib/locales/chupakabra_tools.en.yml +28 -0
- data/lib/locales/chupakabra_tools.ru.yml +28 -0
- metadata +9 -30
- data/lib/chupakabra_tools/active_enum_extended.rb +0 -53
- data/lib/chupakabra_tools/data_type.rb +0 -12
- data/lib/chupakabra_tools/deletion_status.rb +0 -6
- data/lib/chupakabra_tools/education_level.rb +0 -8
- data/lib/chupakabra_tools/file_type.rb +0 -13
- data/lib/chupakabra_tools/internet_file_process_status.rb +0 -9
- data/lib/chupakabra_tools/json_status.rb +0 -12
- data/lib/chupakabra_tools/logging.rb +0 -135
- data/lib/chupakabra_tools/marriage_status.rb +0 -10
- data/lib/chupakabra_tools/predefined_time_intervals.rb +0 -23
- data/lib/chupakabra_tools/set_management_result.rb +0 -9
- data/lib/chupakabra_tools/sex.rb +0 -6
- data/lib/chupakabra_tools/time_interval.rb +0 -542
- data/lib/chupakabra_tools/xml/xml_parser.rb +0 -54
@@ -1,67 +1,67 @@
|
|
1
|
-
module ChupakabraTools
|
2
|
-
|
3
|
-
|
1
|
+
module ChupakabraTools
|
2
|
+
module Convert
|
3
|
+
def self.string_to_value(data, data_type)
|
4
|
+
result_value = nil
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if data
|
7
|
+
data = data.to_s unless data.is_a?(String)
|
8
|
+
data_type = "string" if data_type.nil?
|
9
|
+
data_type = data_type.to_s unless data_type.is_a?(String)
|
10
|
+
data_type.downcase!
|
10
11
|
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
13
|
+
begin
|
14
|
+
result_value = case data_type
|
15
|
+
when "integer", :integer
|
16
|
+
data.to_i
|
17
|
+
when "float", :float, "decimal", :decimal
|
18
|
+
data.to_f
|
19
|
+
when "datetime", :datetime
|
20
|
+
data.to_datetime
|
21
|
+
when "date", :date
|
22
|
+
data.to_date
|
23
|
+
when "time", :time
|
24
|
+
data.to_time
|
25
|
+
when "string", :string, "text", :text
|
26
|
+
data
|
27
|
+
when "boolean", :boolean
|
28
|
+
[1, "1", "true", :true, true].include?(data) ? true : false
|
29
|
+
else
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
#ignored
|
34
|
+
end
|
35
|
+
end
|
36
|
+
result_value
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
39
|
+
def self.value_to_string(data, data_type)
|
40
|
+
result_value = nil
|
41
|
+
data_type.strip! if data_type && data.is_a?(String)
|
42
|
+
begin
|
43
|
+
result_value = case data_type
|
44
|
+
when "integer", :integer
|
45
|
+
data
|
46
|
+
when "float", :float, "decimal", :decimal
|
47
|
+
data
|
48
|
+
when "datetime", :datetime
|
49
|
+
data
|
50
|
+
when "date", :date
|
51
|
+
data
|
52
|
+
when "time", :time
|
53
|
+
when data
|
54
|
+
when "string", :string, "text", :text
|
55
|
+
data
|
56
|
+
when "boolean", :boolean
|
57
|
+
data == "1" || data == "true" || data == "on" ? "true" : "false"
|
58
|
+
else
|
59
|
+
data
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
#ignored
|
63
|
+
end
|
64
|
+
result_value
|
65
|
+
end
|
66
|
+
end
|
67
67
|
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
module ChupakabraTools
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
module ChupakabraTools
|
2
|
+
module Http
|
3
|
+
def self.retrieve_operating_system(user_agent)
|
4
|
+
unless user_agent
|
5
|
+
"Unknown"
|
6
|
+
end
|
7
|
+
if user_agent.downcase.match(/mac/i)
|
8
|
+
"MacOS"
|
9
|
+
elsif user_agent.downcase.match(/windows/i)
|
10
|
+
"Windows"
|
11
|
+
elsif user_agent.downcase.match(/linux/i)
|
12
|
+
"Linux"
|
13
|
+
elsif user_agent.downcase.match(/unix/i)
|
14
|
+
"Unix"
|
15
|
+
else
|
16
|
+
"Unknown"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
18
20
|
end
|
@@ -1,64 +1,66 @@
|
|
1
1
|
#encoding: utf-8
|
2
|
-
module ChupakabraTools
|
2
|
+
module ChupakabraTools
|
3
|
+
module NumberAsText
|
3
4
|
|
4
|
-
|
5
|
+
def self.number_to_russian_string(money)
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
number_strings = Hash.new
|
8
|
+
number_strings[:thousands] = ["тысяч", "тысяча", "тысячи", "тысячи", "тысячи", "тысяч", "тысяч", "тысяч", "тысяч", "тысяч"]
|
9
|
+
number_strings[:millions] = ["миллионов", "миллион", "миллиона", "миллиона", "миллиона", "миллионов", "миллионов", "миллионов", "миллионов", "миллионов"]
|
10
|
+
number_strings[:billions] = ["миллиардов", "миллиард", "миллиарда", "миллиарда", "миллиарда", "миллиардов", "миллиардов", "миллиардов", "миллиардов", "миллиардов"]
|
11
|
+
number_strings[:trillions] = ["триллионов", "триллион", "триллиона", "триллиона", "триллиона", "триллионов", "триллионов", "триллионов", "триллионов", "триллионов"]
|
11
12
|
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
money_trilions = extract_number_order(number, "trillions")
|
15
|
+
if money_trilions > 0
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
end
|
18
|
+
money_billions = extract_number_order(number, "billions")
|
19
|
+
if money_billions > 0
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
end
|
22
|
+
money_millions = extract_number_order(number, "millions")
|
23
|
+
if money_millions > 0
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
end
|
26
|
+
money_thousands = extract_number_order(number, "thousands")
|
27
|
+
if money_thousands > 0
|
27
28
|
|
28
|
-
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
+
money_hundreds = extract_number_order(number, "")
|
31
32
|
|
32
|
-
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def self.format_hundreds(number)
|
36
|
+
number_strings = Hash.new
|
37
|
+
number_strings["1-9"] = ["", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять"]
|
38
|
+
number_strings["10-19"] =["десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать"]
|
39
|
+
number_strings["20-90"] = ["", "", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто"]
|
40
|
+
number_strings["100-900"] = ["", "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот"]
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
money_string = ""
|
43
|
+
money_hundreds = ((number/ 100).to_i * 100 - (number / 1000).to_i * 1000) / 100
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
if money_hundreds > 0
|
46
|
+
money_string += number_strings["100-900"]
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
def self.extract_number_order(number, order)
|
52
|
+
devider = 1
|
53
|
+
if order == "trillions"
|
54
|
+
devider = 1000000000000
|
55
|
+
elsif order == "billions"
|
56
|
+
devider = 1000000000
|
57
|
+
elsif order == "millions"
|
58
|
+
devider = 1000000
|
59
|
+
elsif order == "thousands"
|
60
|
+
devider = 1000
|
61
|
+
end
|
62
|
+
((number/devider).to_i * devider - (number/(devider * 1000)).to_i * devider * 1000)/devider
|
63
|
+
end
|
63
64
|
|
65
|
+
end
|
64
66
|
end
|
@@ -1,52 +1,91 @@
|
|
1
|
-
module ChupakabraTools
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
module ChupakabraTools
|
2
|
+
# Module Responsible for security features
|
3
|
+
module Security
|
4
|
+
# @!method generate_secret
|
5
|
+
# @return [String] generated secret string
|
6
|
+
# @param [Hash] options set of options which influence at a process of secret generation
|
7
|
+
# @option options [Symbol] :big (true) Use Big Letters while generating secret
|
8
|
+
# @option options [Symbol] :small (true) Use Small Letters while generating secret
|
9
|
+
# @option options [Symbol] :digits (true) Use Digits while generating secret
|
10
|
+
# @option options [Symbol] :specials (false) Use Special Signs while generating secret
|
11
|
+
# @option options [Symbol] :length (8) Length of the secret
|
12
|
+
# @option
|
13
|
+
#
|
14
|
+
# @
|
15
|
+
# This method generate secret string based on supplied options
|
16
|
+
def self.generate_secret(options={})
|
17
|
+
options ||= {}
|
18
|
+
options =
|
19
|
+
{
|
20
|
+
big: true,
|
21
|
+
small: true,
|
22
|
+
digits: true,
|
23
|
+
specials: false,
|
24
|
+
length: 8
|
25
|
+
}.merge(options)
|
26
|
+
|
27
|
+
chars = ""
|
28
|
+
|
29
|
+
if options[:small] && options[:small] == true
|
30
|
+
chars += ("a".."z").to_a.join
|
31
|
+
end
|
32
|
+
|
33
|
+
if options[:big] && options[:big] == true
|
34
|
+
chars += ("A".."Z").to_a.join
|
35
|
+
end
|
36
|
+
|
37
|
+
if options[:digits] && options[:digits] == true
|
38
|
+
chars += ("0".."9").to_a.join
|
39
|
+
end
|
40
|
+
|
41
|
+
if options[:specials] && options[:specials] == true
|
42
|
+
chars += "!@#$\%^&*()_+<>/?"
|
43
|
+
end
|
44
|
+
|
45
|
+
if chars.blank?
|
46
|
+
chars = ("a".."z").to_a.join
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
len = 8
|
51
|
+
begin
|
52
|
+
if options[:length] && options[:length].to_i > 5
|
53
|
+
len = options[:length].to_i
|
54
|
+
end
|
55
|
+
rescue
|
56
|
+
end
|
57
|
+
|
58
|
+
new_pass = ""
|
59
|
+
1.upto(len) { |i| new_pass << chars[rand(chars.size-1)] }
|
60
|
+
new_pass
|
61
|
+
end
|
62
|
+
|
63
|
+
# @!method get_password_hash
|
64
|
+
# @param [String] password Password to hash
|
65
|
+
# @param [String] salt Salt for enforcing password protection security. Use nil if you want to hash password without salt
|
66
|
+
# @param [:symbol] algorithm Hashing algorithm. May be one of followings: :sha1, :sha256, :sha512.
|
67
|
+
# Method gets a password hash with or without salt using supplied hashing algorithm. :sha512 is used if an algorithm is not supplied
|
68
|
+
def self.get_password_hash(password, salt, algorithm = nil)
|
69
|
+
data = password
|
70
|
+
data = salt + data if salt && !salt.blank?
|
71
|
+
self.hash_it(data, algorithm)
|
72
|
+
end
|
73
|
+
|
74
|
+
# @!method hash_it
|
75
|
+
# @param [String] data Data to hash
|
76
|
+
# @param [:symbol] algorithm Hashing algorithm: :sha1, :sha256, :sha512.
|
77
|
+
# Method gets a hash using supplied hashing algorithm. :sha512 is used if an algorithm is not supplied
|
78
|
+
def self.hash_it(data, algorithm = nil)
|
79
|
+
case algorithm
|
80
|
+
when :sha1
|
81
|
+
::Digest::SHA1.hexdigest(data)
|
82
|
+
when :sha256
|
83
|
+
::Digest::SHA256.hexdigest(data)
|
84
|
+
when :sha512
|
85
|
+
::Digest::SHA512.hexdigest(data)
|
86
|
+
else
|
87
|
+
::Digest::SHA512.hexdigest(data)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
52
91
|
end
|
@@ -1,38 +1,35 @@
|
|
1
|
-
module ChupakabraTools
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
1
|
+
module ChupakabraTools
|
2
|
+
module Strings
|
3
|
+
def self.cut_string(string, length, options={})
|
4
|
+
options ||= {}
|
5
|
+
options.stringify_keys!
|
6
|
+
|
7
|
+
string ||= ""
|
8
|
+
|
9
|
+
length ||= 30
|
10
|
+
|
11
|
+
if string.length > length
|
12
|
+
string[0..length] + "..."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.trim(str, chars = nil, options = {})
|
17
|
+
# testing "str" for valid string
|
18
|
+
|
19
|
+
options = {force_trim_whitespaces: false}.merge!(options || {})
|
20
|
+
|
21
|
+
return str if str.nil?
|
22
|
+
return nil unless str.is_a?(String)
|
23
|
+
return "" if str.blank?
|
24
|
+
# testing "chars" for valid string
|
25
|
+
return str.strip if chars.nil? || !chars.is_a?(String) || chars.blank? || chars.length > 1
|
26
|
+
result_str = str
|
27
|
+
|
28
|
+
result_str.strip! if options[:force_trim_whitespaces]
|
29
|
+
result_str = result_str.slice(1..result_str.length-1) while result_str.length > 0 && result_str.chr == chars
|
30
|
+
result_str.reverse!
|
31
|
+
result_str = result_str.slice!((1..result_str.length-1)) while result_str.length > 0 && result_str.chr == chars
|
32
|
+
result_str.reverse!
|
33
|
+
end
|
34
|
+
end
|
38
35
|
end
|