chupakabra_tools 0.0.20 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.idea/chupakabra_tools.iml +18 -9
  4. data/.idea/workspace.xml +191 -152
  5. data/Gemfile.lock +21 -26
  6. data/chupakabra_tools.gemspec +2 -2
  7. data/lib/.DS_Store +0 -0
  8. data/lib/chupakabra_tools.rb +7 -21
  9. data/lib/chupakabra_tools/.DS_Store +0 -0
  10. data/lib/chupakabra_tools/active_record.rb +54 -52
  11. data/lib/chupakabra_tools/class_helper.rb +256 -231
  12. data/lib/chupakabra_tools/convert.rb +62 -62
  13. data/lib/chupakabra_tools/http.rb +19 -17
  14. data/lib/chupakabra_tools/number_as_text.rb +48 -46
  15. data/lib/chupakabra_tools/security.rb +90 -51
  16. data/lib/chupakabra_tools/strings.rb +34 -37
  17. data/lib/chupakabra_tools/transliterator.rb +15 -13
  18. data/lib/chupakabra_tools/validations.rb +75 -73
  19. data/lib/chupakabra_tools/xml_parser.rb +52 -0
  20. data/lib/locales/chupakabra_tools.en.yml +28 -0
  21. data/lib/locales/chupakabra_tools.ru.yml +28 -0
  22. metadata +9 -30
  23. data/lib/chupakabra_tools/active_enum_extended.rb +0 -53
  24. data/lib/chupakabra_tools/data_type.rb +0 -12
  25. data/lib/chupakabra_tools/deletion_status.rb +0 -6
  26. data/lib/chupakabra_tools/education_level.rb +0 -8
  27. data/lib/chupakabra_tools/file_type.rb +0 -13
  28. data/lib/chupakabra_tools/internet_file_process_status.rb +0 -9
  29. data/lib/chupakabra_tools/json_status.rb +0 -12
  30. data/lib/chupakabra_tools/logging.rb +0 -135
  31. data/lib/chupakabra_tools/marriage_status.rb +0 -10
  32. data/lib/chupakabra_tools/predefined_time_intervals.rb +0 -23
  33. data/lib/chupakabra_tools/set_management_result.rb +0 -9
  34. data/lib/chupakabra_tools/sex.rb +0 -6
  35. data/lib/chupakabra_tools/time_interval.rb +0 -542
  36. data/lib/chupakabra_tools/xml/xml_parser.rb +0 -54
@@ -1,18 +1,20 @@
1
1
  require "russian"
2
2
 
3
- class ChupakabraTools::Transliterator
3
+ module ChupakabraTools
4
+ class Transliterator
4
5
 
5
- def self.translify(str)
6
- str = str.to_s unless str.is_a?(String)
7
- Russian.transliterate(str)
8
- end
6
+ def self.translify(str)
7
+ str = str.to_s unless str.is_a?(String)
8
+ Russian.transliterate(str)
9
+ end
9
10
 
10
- def self.dirify(str)
11
- result_str = translify(str)
12
- result_str.gsub!(/(\s\&\s)|(\s\&amp\;\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
11
+ def self.dirify(str)
12
+ result_str = translify(str)
13
+ result_str.gsub!(/(\s\&\s)|(\s\&amp\;\s)/, ' and ') # convert & to "and"
14
+ result_str.gsub!(/\W/, ' ') #replace non-chars
15
+ result_str.gsub!(/(_)$/, '') #trailing underscores
16
+ result_str.gsub!(/^(_)/, '') #leading unders
17
+ result_str.strip.gsub(/(\s)/, '-').downcase.squeeze('-')
18
+ end
19
+ end
18
20
  end
@@ -1,88 +1,90 @@
1
1
  #encoding: utf-8
2
- module ChupakabraTools::Validations
3
- def self.russian_letters_template
4
- /^[а-яА-Я\ ]+$/
5
- end
2
+ module ChupakabraTools
3
+ module Validations
4
+ def self.russian_letters_template
5
+ /^[а-яА-Я\ ]+$/
6
+ end
6
7
 
7
- def russian_letters_and_digits
8
- /^[а-яА-Я0-9\ ,;.\-]+$/
9
- end
8
+ def russian_letters_and_digits
9
+ /^[а-яА-Я0-9\ ,;.\-]+$/
10
+ end
10
11
 
11
12
 
12
- def self.validate_phone(phone, params={})
13
+ def self.validate_phone(phone, params={})
13
14
 
14
- params ||= {}
15
+ params ||= {}
15
16
 
16
17
 
17
- if phone.nil?
18
- return params[:allow_nil] && params[:allow_nil] == true
19
- end
18
+ if phone.nil?
19
+ return params[:allow_nil] && params[:allow_nil] == true
20
+ end
20
21
 
21
- unless phone.is_a?(String)
22
- phone = phone.to_s
23
- end
22
+ unless phone.is_a?(String)
23
+ phone = phone.to_s
24
+ end
24
25
 
25
- phone.strip!
26
+ phone.strip!
26
27
 
27
- if phone.blank?
28
- return params[:allow_blank] && params[:allow_blank] == true
29
- end
28
+ if phone.blank?
29
+ return params[:allow_blank] && params[:allow_blank] == true
30
+ end
30
31
 
31
- phone = phone.gsub(/[^0-9]/, "")
32
+ phone = phone.gsub(/[^0-9]/, "")
32
33
 
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
34
+ # checking phone lengths for each country
35
+ if phone.starts_with?("7")
36
+ # for Russia, Kazahstan, Abhazia and so on
37
+ phone = phone.length == 11 ? phone : nil
38
+ #phone += " Russia" if phone
39
+ elsif phone.starts_with?("38")
40
+ # Ukrine
41
+ phone = phone.length == 12 ? phone : nil
42
+ #phone += " Ukraine" if phone
43
+ elsif phone.starts_with?("375")
44
+ # Belarus
45
+ phone = phone.length == 12 ? phone : nil
46
+ #phone += " Belarus" if phone
47
+ elsif phone.starts_with?("370")
48
+ # Litua
49
+ phone = phone.length == 11 ? phone : nil
50
+ #phone += " Litva" if phone
51
+ elsif phone.starts_with?("371")
52
+ # Latvia
53
+ phone = phone.length == 11 ? phone : nil
54
+ #phone += " Latvia" if phone
55
+ elsif phone.starts_with?("372")
56
+ # Estonia
57
+ phone = phone.length == 11 || phone.length == 10 ? phone : nil
58
+ #phone += " Estonia" if phone
59
+ elsif phone.starts_with?("995") && phone.length != 12
60
+ # Geogia
61
+ phone = phone.length == 11 ? phone : nil
62
+ #phone += " Georgia" if phone
63
+ elsif phone.starts_with?("374")
64
+ #Armenia
65
+ phone = phone.length == 11 ? phone : nil
66
+ #phone += " Armenia" if phone
67
+ elsif phone.starts_with?("994")
68
+ # Azerbadzhan
69
+ phone = phone.length == 12 ? phone : nil
70
+ #phone += " Azerbaidzhan" if phone
71
+ elsif phone.starts_with?("373")
72
+ # Moldova
73
+ phone = phone.length == 11 ? phone : nil
74
+ #phone += " Moldova" if phone
75
+ else
76
+ phone = nil
77
+ end
77
78
 
78
- phone ? true : false
79
- end
79
+ phone ? true : false
80
+ end
80
81
 
81
- def self.validate_email(data, params = {})
82
- return false if data.nil?
83
- return false unless data.is_a?(String)
84
- data.strip!
85
- return false if data.blank?
86
- (data =~ /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/) != nil
87
- end
82
+ def self.validate_email(data, params = {})
83
+ return false if data.nil?
84
+ return false unless data.is_a?(String)
85
+ data.strip!
86
+ return false if data.blank?
87
+ (data =~ /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,10}\z/) != nil
88
+ end
89
+ end
88
90
  end
@@ -0,0 +1,52 @@
1
+ module ChupakabraTools
2
+ class XmlParser
3
+ def initialize(node, &block)
4
+ @node = node
5
+ @node.each do
6
+ self.instance_eval &block
7
+ end
8
+ end
9
+
10
+ def name
11
+ @node.name
12
+ end
13
+
14
+ def inner_xml
15
+ @node.inner_xml.strip
16
+ end
17
+
18
+ def outer_xml
19
+ @node.outer_xml.strip
20
+ end
21
+
22
+ def is_start?
23
+ @node.node_type == ::Nokogiri::XML::Reader::TYPE_ELEMENT
24
+ end
25
+
26
+ def is_end?
27
+ @node.node_type == ::Nokogiri::XML::Reader::TYPE_END_ELEMENT
28
+ end
29
+
30
+ def attribute(attribute)
31
+ @node.attribute(attribute)
32
+ end
33
+
34
+ def for_element(name, &block)
35
+ return unless self.name == name and is_start?
36
+ self.instance_eval &block
37
+ end
38
+
39
+ def inside_element(name=nil, &block)
40
+ return if @node.self_closing?
41
+ return unless name.nil? or (self.name == name and is_start?)
42
+
43
+ name = @node.name
44
+ depth = @node.depth
45
+
46
+ @node.each do
47
+ return if self.name == name and is_end? and @node.depth == depth
48
+ self.instance_eval &block
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ en:
2
+ chupakabra_tools:
3
+ api_statuses:
4
+ unknown: "Неизвестен"
5
+ need_authentication: "Требуется аутентификация"
6
+ ok: "ok"
7
+ redirected: "Произошло перенаправелние"
8
+ access_denied: "Доступ запрещен"
9
+ error: "Ошибка"
10
+ record_not_found: "Запись не найдена"
11
+ page_404: "Страница 404"
12
+ database_error: "Ошибка базы данных"
13
+ user_not_found: "Пользователь не найден"
14
+ app_not_found: "Приложение не найдено"
15
+ http_error: "Ошибка протокола HTTP"
16
+ json_response_error: "Неверный JSON ответ от сервера"
17
+ internal_error: "Внутренняя ошибка"
18
+ person_genders:
19
+ man: "мужчина"
20
+ woman: "женщина"
21
+ other: "не важно"
22
+ secret_questions:
23
+ mother_birthplace: "Место рождения Вашей Матери"
24
+ father_birthplace: "Место рождения Вашего Отца"
25
+ best_friend: "Ваш лучший друг детства"
26
+ pet_name: "Кличка Вашего первого домашнего питомца"
27
+ favorite_teacher: "Ваш любимый учитель"
28
+ favorite_caracter: "Ваш любимый персонаж"
@@ -0,0 +1,28 @@
1
+ en:
2
+ chupakabra_tools:
3
+ api_statuses:
4
+ unknown: "Неизвестен"
5
+ need_authentication: "Требуется аутентификация"
6
+ ok: "ok"
7
+ redirected: "Произошло перенаправелние"
8
+ access_denied: "Доступ запрещен"
9
+ error: "Ошибка"
10
+ record_not_found: "Запись не найдена"
11
+ page_404: "Страница 404"
12
+ database_error: "Ошибка базы данных"
13
+ user_not_found: "Пользователь не найден"
14
+ app_not_found: "Приложение не найдено"
15
+ http_error: "Ошибка протокола HTTP"
16
+ json_response_error: "Неверный JSON ответ от сервера"
17
+ internal_error: "Внутренняя ошибка"
18
+ person_genders:
19
+ man: "мужчина"
20
+ woman: "женщина"
21
+ other: "не важно"
22
+ secret_questions:
23
+ mother_birthplace: "Место рождения Вашей Матери"
24
+ father_birthplace: "Место рождения Вашего Отца"
25
+ best_friend: "Ваш лучший друг детства"
26
+ pet_name: "Кличка Вашего первого домашнего питомца"
27
+ favorite_teacher: "Ваш любимый учитель"
28
+ favorite_caracter: "Ваш любимый персонаж"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chupakabra_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitrofanov Dmitry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activerecord
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +87,7 @@ executables: []
101
87
  extensions: []
102
88
  extra_rdoc_files: []
103
89
  files:
90
+ - ".DS_Store"
104
91
  - ".gitignore"
105
92
  - ".idea/.rakeTasks"
106
93
  - ".idea/chupakabra_tools.iml"
@@ -116,30 +103,21 @@ files:
116
103
  - README.md
117
104
  - Rakefile
118
105
  - chupakabra_tools.gemspec
106
+ - lib/.DS_Store
119
107
  - lib/chupakabra_tools.rb
120
- - lib/chupakabra_tools/active_enum_extended.rb
108
+ - lib/chupakabra_tools/.DS_Store
121
109
  - lib/chupakabra_tools/active_record.rb
122
110
  - lib/chupakabra_tools/class_helper.rb
123
111
  - lib/chupakabra_tools/convert.rb
124
- - lib/chupakabra_tools/data_type.rb
125
- - lib/chupakabra_tools/deletion_status.rb
126
- - lib/chupakabra_tools/education_level.rb
127
- - lib/chupakabra_tools/file_type.rb
128
112
  - lib/chupakabra_tools/http.rb
129
- - lib/chupakabra_tools/internet_file_process_status.rb
130
- - lib/chupakabra_tools/json_status.rb
131
- - lib/chupakabra_tools/logging.rb
132
- - lib/chupakabra_tools/marriage_status.rb
133
113
  - lib/chupakabra_tools/number_as_text.rb
134
- - lib/chupakabra_tools/predefined_time_intervals.rb
135
114
  - lib/chupakabra_tools/security.rb
136
- - lib/chupakabra_tools/set_management_result.rb
137
- - lib/chupakabra_tools/sex.rb
138
115
  - lib/chupakabra_tools/strings.rb
139
- - lib/chupakabra_tools/time_interval.rb
140
116
  - lib/chupakabra_tools/transliterator.rb
141
117
  - lib/chupakabra_tools/validations.rb
142
- - lib/chupakabra_tools/xml/xml_parser.rb
118
+ - lib/chupakabra_tools/xml_parser.rb
119
+ - lib/locales/chupakabra_tools.en.yml
120
+ - lib/locales/chupakabra_tools.ru.yml
143
121
  - update/.gitignore
144
122
  - update/Gemfile
145
123
  - update/LICENSE.txt
@@ -172,3 +150,4 @@ signing_key:
172
150
  specification_version: 4
173
151
  summary: Chupakabara Tools
174
152
  test_files: []
153
+ has_rdoc:
@@ -1,53 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require "active_enum"
3
-
4
- class ChupakabraTools::ActiveEnumExtended < ActiveEnum::Base
5
-
6
-
7
- def self.id_by_tag(tag)
8
- self.all.each do |item|
9
- return item[0] if item[2][:tag] == tag
10
- end
11
- nil
12
- end
13
-
14
- def self.tag_by_id(id)
15
- self.all.each do |item|
16
- return item[2][:tag] if item[0] == id
17
- end
18
- nil
19
- end
20
-
21
- def self.all_tags
22
- self.all.map{ |item| item[2][:tag] }
23
- end
24
-
25
- def self.all_ids
26
- self.all.map{ |item| item[0] }
27
- end
28
-
29
- def self.for_select
30
- self.all.map{ |item| [item[1], item[2][:tag]] }
31
- end
32
-
33
- def self.to_hash(data = nil)
34
- unless data
35
- return self.all.map{ |item| {id: item[0], name: item[1], tag: item[2][:tag]} }
36
- end
37
- if data.is_a?(String)
38
- self.all.each do |item|
39
- if item[2][:tag] == data
40
- return {id: item[0], name: item[1], tag: item[2][:tag]}
41
- end
42
- end
43
- end
44
- if data.is_a?(Integer)
45
- self.all.each do |item|
46
- if item[0] == data
47
- return {id: item[0], name: item[1], tag: item[2][:tag]}
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
@@ -1,12 +0,0 @@
1
- require 'chupakabra_tools/active_enum_extended'
2
-
3
- class ChupakabraTools::DataType < ::ChupakabraTools::ActiveEnumExtended
4
- value id: 1, name: I18n.t('chupakabra_tools.data_types.integer'), tag: 'integer'
5
- value id: 2, name: I18n.t('chupakabra_tools.data_types.string'), tag: 'string'
6
- value id: 3, name: I18n.t('chupakabra_tools.data_types.boolean'), tag: 'boolean'
7
- value id: 4, name: I18n.t('chupakabra_tools.data_types.text'), tag: 'text'
8
- value id: 5, name: I18n.t('chupakabra_tools.data_types.decimal'), tag: 'decimal'
9
- value id: 6, name: I18n.t('chupakabra_tools.data_types.date'), tag: 'date'
10
- value id: 7, name: I18n.t('chupakabra_tools.data_types.datetime'), tag: 'datetime'
11
-
12
- end