russian_phone 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/README.md +14 -0
- data/lib/russian_phone/active_record.rb +38 -0
- data/lib/russian_phone/codes.rb +140 -140
- data/lib/russian_phone/field.rb +47 -47
- data/lib/russian_phone/format_validator.rb +13 -13
- data/lib/russian_phone/presence_validator.rb +13 -13
- data/lib/russian_phone/railtie.rb +10 -0
- data/lib/russian_phone/version.rb +1 -1
- data/lib/russian_phone.rb +1 -0
- data/russian_phone.gemspec +8 -2
- data/spec/phone_spec.rb +56 -0
- data/spec/spec_helper.rb +19 -8
- data/spec/support/ar_user.rb +6 -0
- data/spec/support/mongoid.yml +1 -2
- data/spec/support/user.rb +10 -12
- data/spec/support/user_with_any_code.rb +6 -6
- data/spec/support/user_with_required.rb +6 -6
- data/spec/support/user_with_validation.rb +6 -6
- data/spec/support/user_without_validation.rb +7 -7
- metadata +79 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea445f51d66b693b7e0abd1908fdf5b92a6340a4
|
4
|
+
data.tar.gz: f71ad198cca39abe5e9e0cdf9cf626397249c135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed37c2e0dc5a47f4f1b046cc91ae7b6ec7ded479df8c58c3e94f752a1036b8ea33bc2bed7848351a1c215b149520d73e505693fe8ef9dc9040e46adabee42065
|
7
|
+
data.tar.gz: 62d281f2ab91131435b177ce8a00f98ac5f2904184631b572c8eecce839b5dcecb0b94b6835fff8ca34f85c6b5bbe08a06bd13e9da4b857b145a2e04f9c48f65
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -75,6 +75,20 @@ Or install it yourself as:
|
|
75
75
|
# u.phone.valid?
|
76
76
|
=> true
|
77
77
|
|
78
|
+
Использование с ActiveRecord
|
79
|
+
|
80
|
+
class ArUser < ActiveRecord::Base
|
81
|
+
russian_phone :phone
|
82
|
+
russian_phone :validated_phone, default_country: 7, allowed_cities: [495], validate: true
|
83
|
+
end
|
84
|
+
|
85
|
+
# u = ArUser.new(phone: '495 1111111')
|
86
|
+
# u.phone
|
87
|
+
=> '+7 (495) 111-11-11'
|
88
|
+
# u.phone.valid?
|
89
|
+
=> true
|
90
|
+
|
91
|
+
|
78
92
|
Обратите внимание, по умолчанию *валидация телефонного номера выключена*, это значит что номер будет
|
79
93
|
сохраняться в базу даже если гем не смог его разобрать. Включите валидацию, установив validate:true.
|
80
94
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RussianPhone
|
2
|
+
module ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def russian_phone(field, *args)
|
7
|
+
name = field.to_s
|
8
|
+
|
9
|
+
options = args.extract_options! || {}
|
10
|
+
instance_variable_set "@#{name}_phone_options", options
|
11
|
+
|
12
|
+
if options[:validate]
|
13
|
+
validates_with(RussianPhone::FormatValidator, fields: [name])
|
14
|
+
end
|
15
|
+
|
16
|
+
if options[:required]
|
17
|
+
validates_with(RussianPhone::PresenceValidator, fields: [name])
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method name do
|
21
|
+
options = self.class.instance_variable_get("@#{name}_phone_options")
|
22
|
+
RussianPhone::Number.new(read_attribute(name), options)
|
23
|
+
end
|
24
|
+
define_method "#{name}=" do |value|
|
25
|
+
instance_variable_set("@#{name}_phone_before_type_cast", value)
|
26
|
+
options = self.class.instance_variable_get("@#{name}_phone_options")
|
27
|
+
self[name] = RussianPhone::Number.new(value, options).mongoize
|
28
|
+
end
|
29
|
+
define_method "#{name}_phone_before_type_cast" do
|
30
|
+
instance_variable_get "@#{name}_phone_before_type_cast"
|
31
|
+
end
|
32
|
+
after_save do
|
33
|
+
instance_variable_set "@#{name}_phone_before_type_cast", nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/russian_phone/codes.rb
CHANGED
@@ -1,141 +1,141 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module RussianPhone
|
4
|
-
class Codes
|
5
|
-
class << self
|
6
|
-
def ndcs_with_5_subscriber_digits
|
7
|
-
%w(30130 30131 30132 30133 30134 30135 30136 30137 30138 30140 30141 30142 30143 30144
|
8
|
-
30145 30146 30147 30148 30149 30150 30153 30230 30231 30232 30233 30234 30235 30236 30237 30238 30239 30240 30241
|
9
|
-
30242 30243 30244 30245 30246 30247 30248 30249 30251 30252 30253 30255 30256 30257 30261 30262 30264 30265 30266
|
10
|
-
34126 34130 34132 34133 34134 34136 34138 34139 34141 34145 34147 34150 34151 34152 34153 34154 34155 34157 34158
|
11
|
-
34159 34161 34162 34163 34164 34166 34240 34241 34242 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
|
12
|
-
34254 34255 34256 34257 34258 34259 34260 34261 34262 34263 34265 34266 34268 34269 34271 34272 34273 34274 34275
|
13
|
-
34276 34277 34278 34279 34291 34292 34293 34294 34296 34297 34298 34341 34342 34343 34344 34345 34346 34347 34349
|
14
|
-
34350 34355 34356 34357 34358 34360 34361 34362 34363 34364 34365 34367 34368 34369 34370 34371 34372 34373 34374
|
15
|
-
34375 34376 34377 34380 34383 34384 34385 34386 34387 34388 34389 34391 34394 34395 34397 34398 34531 34533 34535
|
16
|
-
34537 34539 34541 34542 34543 34544 34545 34546 34547 34550 34551 34553 34554 34555 34556 34557 34561 34634 34638
|
17
|
-
34643 34667 34668 34669 34670 34672 34673 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
|
18
|
-
34745 34746 34747 34748 34749 34750 34751 34752 34753 34754 34755 34756 34757 34758 34759 34760 34761 34762 34763
|
19
|
-
34764 34765 34766 34767 34768 34769 34770 34771 34772 34773 34774 34775 34776 34777 34778 34779 34780 34781 34782
|
20
|
-
34783 34784 34785 34786 34787 34788 34789 34791 34792 34794 34795 34796 34797 34798 34922 34932 34934 34936 34938
|
21
|
-
34940 34948 34949 34992 34993 34994 34995 34996 34997 35130 35131 35133 35134 35138 35139 35140 35141 35142 35143
|
22
|
-
35144 35145 35146 35147 35148 35149 35150 35151 35152 35153 35154 35155 35156 35157 35158 35159 35160 35161 35163
|
23
|
-
35164 35165 35166 35167 35168 35169 35190 35191 3522 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
|
24
|
-
35240 35241 35242 35243 35244 35245 35247 35248 35249 35251 35252 35253 35256 35257 35330 35331 35332 35333 35334
|
25
|
-
35335 35336 35337 35338 35339 35341 35342 35344 35345 35346 35347 35348 35349 35351 35352 35354 35355 35356 35357
|
26
|
-
35358 35359 35361 35362 35363 35364 35365 35366 35367 35368 35379 38141 38150 38151 38152 38153 38154 38155 38156
|
27
|
-
38157 38158 38159 38160 38161 38162 38163 38164 38165 38166 38167 38168 38169 38170 38171 38172 38173 38174 38175
|
28
|
-
38176 38177 38178 38179 38241 38243 38244 38245 38246 38247 38249 38250 38251 38252 38253 38254 38255 38256 38257
|
29
|
-
38258 38259 38340 38341 38343 38345 38346 38347 38348 38349 38350 38351 38352 38353 38354 38355 38356 38357 38358
|
30
|
-
38359 38360 38361 38362 38363 38364 38365 38366 38367 38368 38369 38371 38372 38373 38441 38442 38443 38444 38445
|
31
|
-
38446 38447 38448 38449 38451 38452 38453 38454 38455 38456 38459 38463 38464 38471 38472 38473 38474 38475 38530
|
32
|
-
38531 38532 38533 38534 38535 38536 38537 38538 38539 38550 38551 38552 38553 38554 38555 38556 38557 38558 38559
|
33
|
-
38560 38561 38562 38563 38564 38565 38566 38567 38568 38569 38570 38571 38572 38573 38574 38575 38576 38577 38578
|
34
|
-
38579 38580 38581 38582 38583 38584 38585 38586 38587 38588 38589 38590 38591 38592 38593 38594 38595 38596 38597
|
35
|
-
38598 38599 38840 38841 38842 38843 38844 38845 38846 38847 38848 38849 39031 39032 39033 39034 39035 39036 39041
|
36
|
-
39042 39044 39045 39046 39047 39131 39132 39133 39134 39135 39136 39137 39138 39139 39140 39141 39142 39143 39144
|
37
|
-
39145 39146 39147 39148 39149 39150 39151 39152 39153 39154 39155 39156 39157 39158 39159 39160 39161 39162 39163
|
38
|
-
39164 39165 39166 39167 39168 39169 39170 39171 39172 39173 39174 39175 39176 39177 39178 39179 39190 39191 39193
|
39
|
-
39195 39196 39197 39198 39199 39432 39433 39434 39435 39436 39437 39438 39439 39441 39442 39444 39445 39450 39451
|
40
|
-
39530 39535 39536 39537 39538 39539 39540 39541 39542 39543 39544 39545 39546 39548 39549 39550 39551 39552 39553
|
41
|
-
39554 39557 39558 39559 39560 39561 39562 39563 39564 39565 39566 39567 39568 39569 40141 40142 40143 40144 40145
|
42
|
-
40150 40151 40152 40153 40155 40156 40157 40158 40159 40161 40162 40163 40164 41131 41132 41133 41134 41135 41136
|
43
|
-
41137 41138 41140 41141 41142 41143 41144 41145 41147 41150 41151 41152 41153 41154 41155 41156 41157 41158 41159
|
44
|
-
41160 41161 41162 41163 41164 41165 41166 41167 41168 41169 41341 41342 41343 41344 41345 41346 41347 41348 41531
|
45
|
-
41532 41533 41534 41535 41536 41537 41538 41539 41541 41542 41543 41544 41545 41546 41547 41548 41634 41636 41637
|
46
|
-
41638 41639 41641 41642 41643 41644 41645 41646 41647 41648 41649 41651 41652 41653 41654 41655 41656 41658 42135
|
47
|
-
42137 42138 42141 42142 42143 42144 42146 42147 42149 42151 42153 42154 42155 42156 42331 42334 42335 42337 42339
|
48
|
-
42344 42345 42346 42347 42349 42351 42352 42354 42355 42356 42357 42359 42361 42362 42363 42365 42371 42372 42373
|
49
|
-
42374 42375 42376 42377 42431 42432 42433 42434 42435 42436 42437 42441 42442 42443 42444 42446 42447 42452 42453
|
50
|
-
42454 42455 42622 42632 42663 42665 42666 42722 42732 42733 42734 42735 42736 42737 42738 42739 47131 47132 47133
|
51
|
-
47134 47135 47136 47137 47140 47141 47142 47143 47144 47145 47146 47147 47148 47149 47150 47151 47152 47153 47154
|
52
|
-
47155 47156 47157 47158 47159 47231 47232 47233 47234 47235 47236 47237 47238 47241 47242 47243 47244 47245 47246
|
53
|
-
47247 47248 47261 47262 47263 47340 47341 47342 47343 47344 47345 47346 47347 47348 47350 47352 47353 47354 47355
|
54
|
-
47356 47357 47361 47362 47363 47364 47365 47366 47367 47370 47371 47372 47374 47375 47376 47391 47394 47395 47396
|
55
|
-
47461 47462 47463 47464 47465 47466 47467 47468 47469 47471 47472 47473 47474 47475 47476 47477 47478 47531 47532
|
56
|
-
47533 47534 47535 47536 47537 47541 47542 47543 47544 47545 47546 47548 47551 47552 47553 47554 47555 47556 47557
|
57
|
-
47558 47559 48130 48131 48132 48133 48134 48135 48136 48137 48138 48139 48140 48141 48142 48143 48144 48145 48146
|
58
|
-
48147 48148 48149 48153 48155 48165 48166 48167 48230 48231 48232 48233 48234 48235 48236 48237 48238 48239 48242
|
59
|
-
48244 48246 48249 48250 48251 48253 48255 48257 48258 48261 48262 48263 48264 48265 48266 48267 48268 48269 48271
|
60
|
-
48272 48273 48274 48275 48276 48330 48331 48332 48333 48334 48335 48336 48338 48339 48340 48341 48342 48343 48344
|
61
|
-
48345 48346 48347 48348 48349 48351 48352 48353 48354 48355 48356 48358 48431 48432 48433 48434 48435 48436 48437
|
62
|
-
48438 48439 48441 48442 48443 48444 48445 48446 48447 48448 48449 48451 48452 48453 48454 48455 48456 48457 48531
|
63
|
-
48532 48533 48534 48535 48536 48538 48539 48542 48543 48544 48545 48546 48547 48549 48640 48642 48643 48644 48645
|
64
|
-
48646 48647 48648 48649 48661 48662 48663 48664 48665 48666 48667 48672 48673 48674 48675 48676 48677 48678 48679
|
65
|
-
48731 48732 48733 48734 48735 48736 48741 48742 48743 48744 48745 48746 48751 48752 48753 48754 48755 48756 48761
|
66
|
-
48762 48763 48766 48767 48768 49130 49131 49132 49133 49135 49136 49137 49138 49139 49141 49142 49143 49144 49145
|
67
|
-
49146 49147 49148 49151 49152 49153 49154 49155 49156 49157 49158 49231 49232 49233 49234 49235 49236 49237 49238
|
68
|
-
49241 49242 49243 49244 49245 49246 49247 49248 49254 49331 49333 49334 49336 49337 49339 49341 49343 49344 49345
|
69
|
-
49346 49347 49349 49351 49352 49353 49354 49355 49356 49357 49430 49431 49432 49433 49434 49435 49436 49437 49438
|
70
|
-
49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 81131 81132 81133 81134
|
71
|
-
81135 81136 81137 81138 81139 81140 81141 81142 81143 81144 81145 81146 81147 81148 81149 81150 81151 81152 81153
|
72
|
-
81361 81362 81363 81364 81365 81366 81367 81368 81369 81370 81371 81372 81373 81374 81375 81376 81378 81379 81430
|
73
|
-
81431 81433 81434 81436 81437 81439 81450 81451 81452 81454 81455 81456 81457 81458 81459 81530 81531 81532 81533
|
74
|
-
81535 81536 81537 81538 81539 81551 81552 81553 81554 81555 81556 81558 81559 81650 81651 81652 81653 81654 81655
|
75
|
-
81656 81657 81658 81659 81660 81661 81662 81663 81664 81665 81666 81667 81668 81669 81732 81733 81737 81738 81739
|
76
|
-
81740 81741 81742 81743 81744 81745 81746 81747 81748 81749 81751 81752 81753 81754 81755 81756 81757 81758 81759
|
77
|
-
81830 81831 81832 81833 81834 81835 81836 81837 81838 81839 81840 81841 81842 81843 81848 81850 81851 81852 81853
|
78
|
-
81854 81855 81856 81858 81859 82130 82131 82132 82133 82134 82135 82136 82137 82138 82139 82140 82141 82142 82144
|
79
|
-
82145 82146 82149 82151 83130 83134 83136 83137 83138 83139 83140 83144 83145 83147 83148 83149 83150 83151 83152
|
80
|
-
83153 83154 83155 83156 83157 83158 83159 83160 83161 83162 83163 83164 83165 83166 83167 83168 83169 83170 83171
|
81
|
-
83172 83173 83174 83175 83176 83177 83178 83179 83190 83191 83192 83193 83194 83195 83196 83197 83330 83331 83332
|
82
|
-
83333 83334 83335 83336 83337 83338 83339 83340 83341 83342 83343 83344 83345 83346 83347 83348 83349 83350 83351
|
83
|
-
83352 83353 83354 83355 83357 83358 83359 83361 83362 83363 83364 83365 83366 83367 83368 83369 83375 83431 83432
|
84
|
-
83433 83434 83436 83437 83438 83439 83441 83442 83443 83444 83445 83446 83447 83448 83449 83451 83453 83454 83456
|
85
|
-
83457 83458 83530 83531 83532 83533 83534 83535 83536 83537 83538 83539 83540 83541 83542 83543 83544 83545 83546
|
86
|
-
83547 83548 83549 83551 83631 83632 83633 83634 83635 83636 83637 83638 83639 83641 83643 83644 83645 84022 84023
|
87
|
-
84024 84025 84026 84027 84028 84140 84141 84142 84143 84144 84145 84146 84147 84148 84150 84151 84152 84153 84154
|
88
|
-
84155 84156 84157 84158 84159 84161 84162 84163 84164 84165 84167 84168 84169 84230 84231 84232 84233 84234 84235
|
89
|
-
84237 84238 84239 84240 84241 84242 84243 84244 84245 84246 84247 84248 84249 84253 84254 84255 84341 84342 84344
|
90
|
-
84345 84346 84347 84348 84360 84361 84362 84364 84365 84366 84367 84368 84369 84370 84371 84373 84374 84375 84376
|
91
|
-
84377 84378 84379 84396 84442 84443 84444 84445 84446 84447 84452 84453 84454 84455 84456 84457 84458 84461 84462
|
92
|
-
84463 84464 84465 84466 84467 84468 84472 84473 84474 84475 84476 84477 84478 84479 84492 84493 84494 84495 84540
|
93
|
-
84542 84543 84544 84545 84548 84549 84550 84551 84552 84554 84555 84557 84558 84560 84561 84562 84563 84564 84565
|
94
|
-
84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84630 84635 84639 84646
|
95
|
-
84647 84648 84650 84651 84652 84653 84654 84655 84656 84657 84658 84660 84661 84663 84664 84666 84667 84670 84671
|
96
|
-
84672 84673 84674 84675 84676 84677 84722 84731 84732 84733 84734 84735 84736 84741 84742 84743 84744 84745 84746
|
97
|
-
84747 84862 85140 85141 85142 85143 85144 85145 85146 85147 85148 85149 85171 85172 85549 85551 85552 85555 85556
|
98
|
-
85557 85558 85559 85563 85569 85592 85593 85594 85595 86130 86131 86132 86133 86135 86137 86138 86140 86141 86142
|
99
|
-
86143 86144 86145 86146 86147 86148 86149 86150 86151 86152 86153 86154 86155 86156 86157 86158 86159 86160 86161
|
100
|
-
86162 86163 86164 86165 86166 86167 86168 86169 86191 86192 86193 86195 86196 86340 86341 86342 86345 86347 86348
|
101
|
-
86349 86350 86351 86353 86354 86355 86356 86357 86358 86359 86360 86361 86363 86364 86365 86367 86368 86369 86370
|
102
|
-
86371 86372 86373 86374 86375 86376 86377 86378 86379 86382 86383 86384 86385 86386 86387 86388 86389 86391 86393
|
103
|
-
86394 86395 86396 86397 86540 86541 86542 86543 86544 86545 86546 86547 86548 86549 86550 86552 86553 86554 86555
|
104
|
-
86556 86557 86558 86559 86560 86563 86565 86630 86631 86632 86633 86634 86635 86636 86637 86638 86731 86732 86733
|
105
|
-
86734 86735 86736 86737 86738 86739 87132 87134 87135 87136 87142 87143 87145 87146 87147 87148 87152 87154 87155
|
106
|
-
87156 87164 87230 87231 87232 87233 87234 87235 87236 87237 87238 87239 87240 87242 87243 87244 87245 87246 87247
|
107
|
-
87248 87249 87252 87254 87255 87256 87257 87258 87259 87260 87261 87262 87263 87264 87265 87266 87267 87268 87271
|
108
|
-
87272 87273 87274 87275 87276 87279 87341 87342 87343 87344 87345 87770 87771 87772 87773 87777 87778 87779 87870
|
109
|
-
87872 87873 87874 87875 87876 87877 87878 87879 87922 87932 87934 87935 87937 87938 87951 87961 87964
|
110
|
-
)
|
111
|
-
end
|
112
|
-
|
113
|
-
def ndcs_with_6_subscriber_digits
|
114
|
-
%w(3012 3022 3412 3435 3439 3452 3456 3462 3463 3466 3473 3494 3496 3513 3519 3532 3537
|
115
|
-
3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162 4212 4217 423 4234
|
116
|
-
4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942 8112 8142 8152 8162
|
117
|
-
8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557 8617
|
118
|
-
862 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
|
119
|
-
)
|
120
|
-
end
|
121
|
-
|
122
|
-
def ndcs_with_7_subscriber_digits
|
123
|
-
%w(342 343 347 351 383 391 473 495 496 498 499 812 818 831 843 844 846 861 862 863)
|
124
|
-
end
|
125
|
-
|
126
|
-
def cell_codes
|
127
|
-
%w(901 902 903 904 905 906 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 936 937 938 950 951 952 953 960 961 962 963 964 965 967 980 981 982 983 984 985 987 988 989 997)
|
128
|
-
end
|
129
|
-
|
130
|
-
def codes_for(digits)
|
131
|
-
if digits == 7
|
132
|
-
ndcs_with_7_subscriber_digits + cell_codes
|
133
|
-
elsif digits == 6
|
134
|
-
ndcs_with_6_subscriber_digits
|
135
|
-
elsif digits == 5
|
136
|
-
ndcs_with_5_subscriber_digits
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RussianPhone
|
4
|
+
class Codes
|
5
|
+
class << self
|
6
|
+
def ndcs_with_5_subscriber_digits
|
7
|
+
%w(30130 30131 30132 30133 30134 30135 30136 30137 30138 30140 30141 30142 30143 30144
|
8
|
+
30145 30146 30147 30148 30149 30150 30153 30230 30231 30232 30233 30234 30235 30236 30237 30238 30239 30240 30241
|
9
|
+
30242 30243 30244 30245 30246 30247 30248 30249 30251 30252 30253 30255 30256 30257 30261 30262 30264 30265 30266
|
10
|
+
34126 34130 34132 34133 34134 34136 34138 34139 34141 34145 34147 34150 34151 34152 34153 34154 34155 34157 34158
|
11
|
+
34159 34161 34162 34163 34164 34166 34240 34241 34242 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
|
12
|
+
34254 34255 34256 34257 34258 34259 34260 34261 34262 34263 34265 34266 34268 34269 34271 34272 34273 34274 34275
|
13
|
+
34276 34277 34278 34279 34291 34292 34293 34294 34296 34297 34298 34341 34342 34343 34344 34345 34346 34347 34349
|
14
|
+
34350 34355 34356 34357 34358 34360 34361 34362 34363 34364 34365 34367 34368 34369 34370 34371 34372 34373 34374
|
15
|
+
34375 34376 34377 34380 34383 34384 34385 34386 34387 34388 34389 34391 34394 34395 34397 34398 34531 34533 34535
|
16
|
+
34537 34539 34541 34542 34543 34544 34545 34546 34547 34550 34551 34553 34554 34555 34556 34557 34561 34634 34638
|
17
|
+
34643 34667 34668 34669 34670 34672 34673 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
|
18
|
+
34745 34746 34747 34748 34749 34750 34751 34752 34753 34754 34755 34756 34757 34758 34759 34760 34761 34762 34763
|
19
|
+
34764 34765 34766 34767 34768 34769 34770 34771 34772 34773 34774 34775 34776 34777 34778 34779 34780 34781 34782
|
20
|
+
34783 34784 34785 34786 34787 34788 34789 34791 34792 34794 34795 34796 34797 34798 34922 34932 34934 34936 34938
|
21
|
+
34940 34948 34949 34992 34993 34994 34995 34996 34997 35130 35131 35133 35134 35138 35139 35140 35141 35142 35143
|
22
|
+
35144 35145 35146 35147 35148 35149 35150 35151 35152 35153 35154 35155 35156 35157 35158 35159 35160 35161 35163
|
23
|
+
35164 35165 35166 35167 35168 35169 35190 35191 3522 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
|
24
|
+
35240 35241 35242 35243 35244 35245 35247 35248 35249 35251 35252 35253 35256 35257 35330 35331 35332 35333 35334
|
25
|
+
35335 35336 35337 35338 35339 35341 35342 35344 35345 35346 35347 35348 35349 35351 35352 35354 35355 35356 35357
|
26
|
+
35358 35359 35361 35362 35363 35364 35365 35366 35367 35368 35379 38141 38150 38151 38152 38153 38154 38155 38156
|
27
|
+
38157 38158 38159 38160 38161 38162 38163 38164 38165 38166 38167 38168 38169 38170 38171 38172 38173 38174 38175
|
28
|
+
38176 38177 38178 38179 38241 38243 38244 38245 38246 38247 38249 38250 38251 38252 38253 38254 38255 38256 38257
|
29
|
+
38258 38259 38340 38341 38343 38345 38346 38347 38348 38349 38350 38351 38352 38353 38354 38355 38356 38357 38358
|
30
|
+
38359 38360 38361 38362 38363 38364 38365 38366 38367 38368 38369 38371 38372 38373 38441 38442 38443 38444 38445
|
31
|
+
38446 38447 38448 38449 38451 38452 38453 38454 38455 38456 38459 38463 38464 38471 38472 38473 38474 38475 38530
|
32
|
+
38531 38532 38533 38534 38535 38536 38537 38538 38539 38550 38551 38552 38553 38554 38555 38556 38557 38558 38559
|
33
|
+
38560 38561 38562 38563 38564 38565 38566 38567 38568 38569 38570 38571 38572 38573 38574 38575 38576 38577 38578
|
34
|
+
38579 38580 38581 38582 38583 38584 38585 38586 38587 38588 38589 38590 38591 38592 38593 38594 38595 38596 38597
|
35
|
+
38598 38599 38840 38841 38842 38843 38844 38845 38846 38847 38848 38849 39031 39032 39033 39034 39035 39036 39041
|
36
|
+
39042 39044 39045 39046 39047 39131 39132 39133 39134 39135 39136 39137 39138 39139 39140 39141 39142 39143 39144
|
37
|
+
39145 39146 39147 39148 39149 39150 39151 39152 39153 39154 39155 39156 39157 39158 39159 39160 39161 39162 39163
|
38
|
+
39164 39165 39166 39167 39168 39169 39170 39171 39172 39173 39174 39175 39176 39177 39178 39179 39190 39191 39193
|
39
|
+
39195 39196 39197 39198 39199 39432 39433 39434 39435 39436 39437 39438 39439 39441 39442 39444 39445 39450 39451
|
40
|
+
39530 39535 39536 39537 39538 39539 39540 39541 39542 39543 39544 39545 39546 39548 39549 39550 39551 39552 39553
|
41
|
+
39554 39557 39558 39559 39560 39561 39562 39563 39564 39565 39566 39567 39568 39569 40141 40142 40143 40144 40145
|
42
|
+
40150 40151 40152 40153 40155 40156 40157 40158 40159 40161 40162 40163 40164 41131 41132 41133 41134 41135 41136
|
43
|
+
41137 41138 41140 41141 41142 41143 41144 41145 41147 41150 41151 41152 41153 41154 41155 41156 41157 41158 41159
|
44
|
+
41160 41161 41162 41163 41164 41165 41166 41167 41168 41169 41341 41342 41343 41344 41345 41346 41347 41348 41531
|
45
|
+
41532 41533 41534 41535 41536 41537 41538 41539 41541 41542 41543 41544 41545 41546 41547 41548 41634 41636 41637
|
46
|
+
41638 41639 41641 41642 41643 41644 41645 41646 41647 41648 41649 41651 41652 41653 41654 41655 41656 41658 42135
|
47
|
+
42137 42138 42141 42142 42143 42144 42146 42147 42149 42151 42153 42154 42155 42156 42331 42334 42335 42337 42339
|
48
|
+
42344 42345 42346 42347 42349 42351 42352 42354 42355 42356 42357 42359 42361 42362 42363 42365 42371 42372 42373
|
49
|
+
42374 42375 42376 42377 42431 42432 42433 42434 42435 42436 42437 42441 42442 42443 42444 42446 42447 42452 42453
|
50
|
+
42454 42455 42622 42632 42663 42665 42666 42722 42732 42733 42734 42735 42736 42737 42738 42739 47131 47132 47133
|
51
|
+
47134 47135 47136 47137 47140 47141 47142 47143 47144 47145 47146 47147 47148 47149 47150 47151 47152 47153 47154
|
52
|
+
47155 47156 47157 47158 47159 47231 47232 47233 47234 47235 47236 47237 47238 47241 47242 47243 47244 47245 47246
|
53
|
+
47247 47248 47261 47262 47263 47340 47341 47342 47343 47344 47345 47346 47347 47348 47350 47352 47353 47354 47355
|
54
|
+
47356 47357 47361 47362 47363 47364 47365 47366 47367 47370 47371 47372 47374 47375 47376 47391 47394 47395 47396
|
55
|
+
47461 47462 47463 47464 47465 47466 47467 47468 47469 47471 47472 47473 47474 47475 47476 47477 47478 47531 47532
|
56
|
+
47533 47534 47535 47536 47537 47541 47542 47543 47544 47545 47546 47548 47551 47552 47553 47554 47555 47556 47557
|
57
|
+
47558 47559 48130 48131 48132 48133 48134 48135 48136 48137 48138 48139 48140 48141 48142 48143 48144 48145 48146
|
58
|
+
48147 48148 48149 48153 48155 48165 48166 48167 48230 48231 48232 48233 48234 48235 48236 48237 48238 48239 48242
|
59
|
+
48244 48246 48249 48250 48251 48253 48255 48257 48258 48261 48262 48263 48264 48265 48266 48267 48268 48269 48271
|
60
|
+
48272 48273 48274 48275 48276 48330 48331 48332 48333 48334 48335 48336 48338 48339 48340 48341 48342 48343 48344
|
61
|
+
48345 48346 48347 48348 48349 48351 48352 48353 48354 48355 48356 48358 48431 48432 48433 48434 48435 48436 48437
|
62
|
+
48438 48439 48441 48442 48443 48444 48445 48446 48447 48448 48449 48451 48452 48453 48454 48455 48456 48457 48531
|
63
|
+
48532 48533 48534 48535 48536 48538 48539 48542 48543 48544 48545 48546 48547 48549 48640 48642 48643 48644 48645
|
64
|
+
48646 48647 48648 48649 48661 48662 48663 48664 48665 48666 48667 48672 48673 48674 48675 48676 48677 48678 48679
|
65
|
+
48731 48732 48733 48734 48735 48736 48741 48742 48743 48744 48745 48746 48751 48752 48753 48754 48755 48756 48761
|
66
|
+
48762 48763 48766 48767 48768 49130 49131 49132 49133 49135 49136 49137 49138 49139 49141 49142 49143 49144 49145
|
67
|
+
49146 49147 49148 49151 49152 49153 49154 49155 49156 49157 49158 49231 49232 49233 49234 49235 49236 49237 49238
|
68
|
+
49241 49242 49243 49244 49245 49246 49247 49248 49254 49331 49333 49334 49336 49337 49339 49341 49343 49344 49345
|
69
|
+
49346 49347 49349 49351 49352 49353 49354 49355 49356 49357 49430 49431 49432 49433 49434 49435 49436 49437 49438
|
70
|
+
49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 81131 81132 81133 81134
|
71
|
+
81135 81136 81137 81138 81139 81140 81141 81142 81143 81144 81145 81146 81147 81148 81149 81150 81151 81152 81153
|
72
|
+
81361 81362 81363 81364 81365 81366 81367 81368 81369 81370 81371 81372 81373 81374 81375 81376 81378 81379 81430
|
73
|
+
81431 81433 81434 81436 81437 81439 81450 81451 81452 81454 81455 81456 81457 81458 81459 81530 81531 81532 81533
|
74
|
+
81535 81536 81537 81538 81539 81551 81552 81553 81554 81555 81556 81558 81559 81650 81651 81652 81653 81654 81655
|
75
|
+
81656 81657 81658 81659 81660 81661 81662 81663 81664 81665 81666 81667 81668 81669 81732 81733 81737 81738 81739
|
76
|
+
81740 81741 81742 81743 81744 81745 81746 81747 81748 81749 81751 81752 81753 81754 81755 81756 81757 81758 81759
|
77
|
+
81830 81831 81832 81833 81834 81835 81836 81837 81838 81839 81840 81841 81842 81843 81848 81850 81851 81852 81853
|
78
|
+
81854 81855 81856 81858 81859 82130 82131 82132 82133 82134 82135 82136 82137 82138 82139 82140 82141 82142 82144
|
79
|
+
82145 82146 82149 82151 83130 83134 83136 83137 83138 83139 83140 83144 83145 83147 83148 83149 83150 83151 83152
|
80
|
+
83153 83154 83155 83156 83157 83158 83159 83160 83161 83162 83163 83164 83165 83166 83167 83168 83169 83170 83171
|
81
|
+
83172 83173 83174 83175 83176 83177 83178 83179 83190 83191 83192 83193 83194 83195 83196 83197 83330 83331 83332
|
82
|
+
83333 83334 83335 83336 83337 83338 83339 83340 83341 83342 83343 83344 83345 83346 83347 83348 83349 83350 83351
|
83
|
+
83352 83353 83354 83355 83357 83358 83359 83361 83362 83363 83364 83365 83366 83367 83368 83369 83375 83431 83432
|
84
|
+
83433 83434 83436 83437 83438 83439 83441 83442 83443 83444 83445 83446 83447 83448 83449 83451 83453 83454 83456
|
85
|
+
83457 83458 83530 83531 83532 83533 83534 83535 83536 83537 83538 83539 83540 83541 83542 83543 83544 83545 83546
|
86
|
+
83547 83548 83549 83551 83631 83632 83633 83634 83635 83636 83637 83638 83639 83641 83643 83644 83645 84022 84023
|
87
|
+
84024 84025 84026 84027 84028 84140 84141 84142 84143 84144 84145 84146 84147 84148 84150 84151 84152 84153 84154
|
88
|
+
84155 84156 84157 84158 84159 84161 84162 84163 84164 84165 84167 84168 84169 84230 84231 84232 84233 84234 84235
|
89
|
+
84237 84238 84239 84240 84241 84242 84243 84244 84245 84246 84247 84248 84249 84253 84254 84255 84341 84342 84344
|
90
|
+
84345 84346 84347 84348 84360 84361 84362 84364 84365 84366 84367 84368 84369 84370 84371 84373 84374 84375 84376
|
91
|
+
84377 84378 84379 84396 84442 84443 84444 84445 84446 84447 84452 84453 84454 84455 84456 84457 84458 84461 84462
|
92
|
+
84463 84464 84465 84466 84467 84468 84472 84473 84474 84475 84476 84477 84478 84479 84492 84493 84494 84495 84540
|
93
|
+
84542 84543 84544 84545 84548 84549 84550 84551 84552 84554 84555 84557 84558 84560 84561 84562 84563 84564 84565
|
94
|
+
84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84630 84635 84639 84646
|
95
|
+
84647 84648 84650 84651 84652 84653 84654 84655 84656 84657 84658 84660 84661 84663 84664 84666 84667 84670 84671
|
96
|
+
84672 84673 84674 84675 84676 84677 84722 84731 84732 84733 84734 84735 84736 84741 84742 84743 84744 84745 84746
|
97
|
+
84747 84862 85140 85141 85142 85143 85144 85145 85146 85147 85148 85149 85171 85172 85549 85551 85552 85555 85556
|
98
|
+
85557 85558 85559 85563 85569 85592 85593 85594 85595 86130 86131 86132 86133 86135 86137 86138 86140 86141 86142
|
99
|
+
86143 86144 86145 86146 86147 86148 86149 86150 86151 86152 86153 86154 86155 86156 86157 86158 86159 86160 86161
|
100
|
+
86162 86163 86164 86165 86166 86167 86168 86169 86191 86192 86193 86195 86196 86340 86341 86342 86345 86347 86348
|
101
|
+
86349 86350 86351 86353 86354 86355 86356 86357 86358 86359 86360 86361 86363 86364 86365 86367 86368 86369 86370
|
102
|
+
86371 86372 86373 86374 86375 86376 86377 86378 86379 86382 86383 86384 86385 86386 86387 86388 86389 86391 86393
|
103
|
+
86394 86395 86396 86397 86540 86541 86542 86543 86544 86545 86546 86547 86548 86549 86550 86552 86553 86554 86555
|
104
|
+
86556 86557 86558 86559 86560 86563 86565 86630 86631 86632 86633 86634 86635 86636 86637 86638 86731 86732 86733
|
105
|
+
86734 86735 86736 86737 86738 86739 87132 87134 87135 87136 87142 87143 87145 87146 87147 87148 87152 87154 87155
|
106
|
+
87156 87164 87230 87231 87232 87233 87234 87235 87236 87237 87238 87239 87240 87242 87243 87244 87245 87246 87247
|
107
|
+
87248 87249 87252 87254 87255 87256 87257 87258 87259 87260 87261 87262 87263 87264 87265 87266 87267 87268 87271
|
108
|
+
87272 87273 87274 87275 87276 87279 87341 87342 87343 87344 87345 87770 87771 87772 87773 87777 87778 87779 87870
|
109
|
+
87872 87873 87874 87875 87876 87877 87878 87879 87922 87932 87934 87935 87937 87938 87951 87961 87964
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
def ndcs_with_6_subscriber_digits
|
114
|
+
%w(3012 3022 3412 3435 3439 3452 3456 3462 3463 3466 3473 3494 3496 3513 3519 3532 3537
|
115
|
+
3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162 4212 4217 423 4234
|
116
|
+
4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942 8112 8142 8152 8162
|
117
|
+
8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557 8617
|
118
|
+
862 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
def ndcs_with_7_subscriber_digits
|
123
|
+
%w(342 343 347 351 383 391 473 495 496 498 499 812 818 831 843 844 846 861 862 863)
|
124
|
+
end
|
125
|
+
|
126
|
+
def cell_codes
|
127
|
+
%w(901 902 903 904 905 906 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 936 937 938 950 951 952 953 960 961 962 963 964 965 967 980 981 982 983 984 985 987 988 989 997)
|
128
|
+
end
|
129
|
+
|
130
|
+
def codes_for(digits)
|
131
|
+
if digits == 7
|
132
|
+
ndcs_with_7_subscriber_digits + cell_codes
|
133
|
+
elsif digits == 6
|
134
|
+
ndcs_with_6_subscriber_digits
|
135
|
+
elsif digits == 5
|
136
|
+
ndcs_with_5_subscriber_digits
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
141
|
end
|
data/lib/russian_phone/field.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module RussianPhone
|
4
|
-
class Field
|
5
|
-
attr_accessor :options
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
@options = Number.process_options(options)
|
9
|
-
end
|
10
|
-
|
11
|
-
::Mongoid::Fields.option :validate do |model, field, value|
|
12
|
-
if value
|
13
|
-
model.validates_with(RussianPhone::FormatValidator, fields: [field.name])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
::Mongoid::Fields.option :required do |model, field, value|
|
18
|
-
if value
|
19
|
-
model.validates_with(RussianPhone::PresenceValidator, fields: [field.name])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Get the object as it was stored in the database, and instantiate
|
24
|
-
# this custom class from it.
|
25
|
-
def demongoize(object)
|
26
|
-
RussianPhone::Number.new(object, @options)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Takes any possible object and converts it to how it would be
|
30
|
-
# stored in the database.
|
31
|
-
def mongoize(object)
|
32
|
-
case object
|
33
|
-
when RussianPhone::Number then object.mongoize
|
34
|
-
when String then RussianPhone::Number.new(object, @options).mongoize
|
35
|
-
else object
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Converts the object that was supplied to a criteria and converts it
|
40
|
-
# into a database friendly form.
|
41
|
-
def evolve(object)
|
42
|
-
case object
|
43
|
-
when RussianPhone::Number then object.mongoize
|
44
|
-
else object
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RussianPhone
|
4
|
+
class Field
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@options = Number.process_options(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
::Mongoid::Fields.option :validate do |model, field, value|
|
12
|
+
if value
|
13
|
+
model.validates_with(RussianPhone::FormatValidator, fields: [field.name])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
::Mongoid::Fields.option :required do |model, field, value|
|
18
|
+
if value
|
19
|
+
model.validates_with(RussianPhone::PresenceValidator, fields: [field.name])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the object as it was stored in the database, and instantiate
|
24
|
+
# this custom class from it.
|
25
|
+
def demongoize(object)
|
26
|
+
RussianPhone::Number.new(object, @options)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Takes any possible object and converts it to how it would be
|
30
|
+
# stored in the database.
|
31
|
+
def mongoize(object)
|
32
|
+
case object
|
33
|
+
when RussianPhone::Number then object.mongoize
|
34
|
+
when String then RussianPhone::Number.new(object, @options).mongoize
|
35
|
+
else object
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Converts the object that was supplied to a criteria and converts it
|
40
|
+
# into a database friendly form.
|
41
|
+
def evolve(object)
|
42
|
+
case object
|
43
|
+
when RussianPhone::Number then object.mongoize
|
44
|
+
else object
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
48
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module RussianPhone
|
4
|
-
class FormatValidator < ActiveModel::Validator
|
5
|
-
def validate(record)
|
6
|
-
options[:fields].each do |field|
|
7
|
-
unless record.send(field).phone.blank?
|
8
|
-
record.errors[field] << 'Неверный телефонный номер' unless record.send(field).valid? && record.send(field).city_allowed?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RussianPhone
|
4
|
+
class FormatValidator < ActiveModel::Validator
|
5
|
+
def validate(record)
|
6
|
+
options[:fields].each do |field|
|
7
|
+
unless record.send(field).phone.blank?
|
8
|
+
record.errors[field] << 'Неверный телефонный номер' unless record.send(field).valid? && record.send(field).city_allowed?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module RussianPhone
|
4
|
-
class PresenceValidator < ActiveModel::Validator
|
5
|
-
def validate(record)
|
6
|
-
options[:fields].each do |field|
|
7
|
-
if record.send(field).phone.blank?
|
8
|
-
record.errors[field] << 'Необходимо заполнить'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module RussianPhone
|
4
|
+
class PresenceValidator < ActiveModel::Validator
|
5
|
+
def validate(record)
|
6
|
+
options[:fields].each do |field|
|
7
|
+
if record.send(field).phone.blank?
|
8
|
+
record.errors[field] << 'Необходимо заполнить'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/russian_phone.rb
CHANGED
data/russian_phone.gemspec
CHANGED
@@ -18,11 +18,17 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
|
21
|
-
gem.add_runtime_dependency 'mongoid', '>= 3.0.0'
|
22
21
|
|
22
|
+
gem.add_development_dependency 'mongoid', '>= 3.0.0'
|
23
|
+
gem.add_development_dependency "rails", ">= 3.0"
|
24
|
+
gem.add_development_dependency "rspec", "~> 2.14.0"
|
25
|
+
gem.add_development_dependency 'sqlite3'
|
26
|
+
gem.add_development_dependency "rspec-rails", "~> 2.14"
|
27
|
+
gem.add_development_dependency 'activerecord'
|
23
28
|
gem.add_development_dependency 'bundler'
|
24
29
|
gem.add_development_dependency 'rake'
|
25
|
-
gem.add_development_dependency 'rspec'
|
26
30
|
gem.add_development_dependency 'simplecov'
|
31
|
+
gem.add_development_dependency 'pry'
|
27
32
|
gem.add_development_dependency 'database_cleaner'
|
28
33
|
end
|
34
|
+
|
data/spec/phone_spec.rb
CHANGED
@@ -342,6 +342,62 @@ describe RussianPhone do
|
|
342
342
|
end
|
343
343
|
end
|
344
344
|
|
345
|
+
describe 'when storing with activerecord' do
|
346
|
+
it 'should parse, store and retrieve numbers correctly' do
|
347
|
+
u = ArUser.new(name: 'test', phone: '906 111 11 11')
|
348
|
+
u.save.should be_true
|
349
|
+
u = ArUser.first
|
350
|
+
u.phone.should eq '+7 (906) 111-11-11'
|
351
|
+
u.phone.cell?.should be_true
|
352
|
+
u.phone.free?.should be_false
|
353
|
+
|
354
|
+
u.phone.clean.should eq '79061111111'
|
355
|
+
|
356
|
+
u.phone.country.should eq '7'
|
357
|
+
u.phone.city.should eq '906'
|
358
|
+
u.phone.subscriber.should eq '1111111'
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'should fail validation when validate is on and phone is invalid' do
|
362
|
+
u = ArUser.new(validated_phone: '123')
|
363
|
+
u.valid?.should be_false
|
364
|
+
u.save.should be_false
|
365
|
+
u.errors.messages.should eq({:validated_phone =>["Неверный телефонный номер"]})
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'should pass validation when validate is on and phone is valid' do
|
369
|
+
u = ArUser.new(validated_phone: '495 121 11 11')
|
370
|
+
u.valid?.should be_true
|
371
|
+
u.save.should be_true
|
372
|
+
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
373
|
+
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'should pass validation when validate is on and phone is valid' do
|
377
|
+
u = ArUser.new(validated_phone: '7495 121 11 11')
|
378
|
+
u.valid?.should be_true
|
379
|
+
u.save.should be_true
|
380
|
+
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
381
|
+
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'should pass validation when validate is on and phone is valid' do
|
385
|
+
u = ArUser.new(validated_phone: '7 495 121 11 11')
|
386
|
+
u.valid?.should be_true
|
387
|
+
u.save.should be_true
|
388
|
+
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
389
|
+
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should pass validation when validate is on and phone is valid' do
|
393
|
+
u = ArUser.new(validated_phone: '8495 121 11 11')
|
394
|
+
u.valid?.should be_true
|
395
|
+
u.save.should be_true
|
396
|
+
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
397
|
+
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
345
401
|
describe 'when storing with mongoid' do
|
346
402
|
it 'should parse, store and retrieve numbers correctly' do
|
347
403
|
u = User.new(name: 'test', phone: '906 111 11 11')
|
data/spec/spec_helper.rb
CHANGED
@@ -5,22 +5,32 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
5
5
|
require 'rspec'
|
6
6
|
require 'simplecov'
|
7
7
|
require 'mongoid'
|
8
|
-
|
8
|
+
require 'active_record'
|
9
9
|
require 'database_cleaner'
|
10
|
-
|
10
|
+
require 'pry'
|
11
11
|
SimpleCov.start
|
12
|
-
|
13
12
|
require 'russian_phone'
|
14
13
|
|
15
|
-
# Requires supporting files with custom matchers and macros, etc,
|
16
|
-
# in ./support/ and its subdirectories.
|
17
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
18
|
-
|
19
14
|
Mongoid.configure do |config|
|
20
15
|
ENV["MONGOID_ENV"] = "test"
|
21
16
|
Mongoid.load!("spec/support/mongoid.yml")
|
22
17
|
end
|
23
18
|
|
19
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
20
|
+
ActiveRecord::Schema.define do
|
21
|
+
self.verbose = false
|
22
|
+
create_table :ar_users, force: true do |t|
|
23
|
+
t.string :name
|
24
|
+
t.string :phone
|
25
|
+
t.string :validated_phone
|
26
|
+
end
|
27
|
+
end
|
28
|
+
ActiveRecord::Base.send :include, RussianPhone::ActiveRecord
|
29
|
+
|
30
|
+
# Requires supporting files with custom matchers and macros, etc,
|
31
|
+
# in ./support/ and its subdirectories.
|
32
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
33
|
+
|
24
34
|
DatabaseCleaner.orm = "mongoid"
|
25
35
|
|
26
36
|
RSpec.configure do |config|
|
@@ -34,7 +44,8 @@ RSpec.configure do |config|
|
|
34
44
|
|
35
45
|
config.after(:each) do
|
36
46
|
DatabaseCleaner.clean
|
47
|
+
ArUser.destroy_all
|
37
48
|
end
|
38
49
|
|
39
50
|
config.mock_with :rspec
|
40
|
-
end
|
51
|
+
end
|
data/spec/support/mongoid.yml
CHANGED
data/spec/support/user.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
field :
|
7
|
-
|
8
|
-
field :
|
9
|
-
|
10
|
-
|
11
|
-
field :phone_in_812, type: RussianPhone.field(default_country: 7, default_city: '812')
|
12
|
-
end
|
1
|
+
class User
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :name
|
5
|
+
|
6
|
+
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495])
|
7
|
+
|
8
|
+
field :phone_in_495, type: RussianPhone.field(default_country: 7, default_city: '495')
|
9
|
+
field :phone_in_812, type: RussianPhone.field(default_country: 7, default_city: '812')
|
10
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
class UserWithAnyCode
|
4
|
-
include Mongoid::Document
|
5
|
-
|
6
|
-
field :phone, type: RussianPhone.field(default_country: 7), validate: true
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class UserWithAnyCode
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :phone, type: RussianPhone.field(default_country: 7), validate: true
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
class UserWithRequired
|
4
|
-
include Mongoid::Document
|
5
|
-
|
6
|
-
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495]), validate: false, required: true
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class UserWithRequired
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495]), validate: false, required: true
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
class UserWithValidation
|
4
|
-
include Mongoid::Document
|
5
|
-
|
6
|
-
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495]), validate: true
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class UserWithValidation
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495]), validate: true
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
class UserWithoutValidation
|
4
|
-
include Mongoid::Document
|
5
|
-
|
6
|
-
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495])
|
7
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class UserWithoutValidation
|
4
|
+
include Mongoid::Document
|
5
|
+
|
6
|
+
field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495])
|
7
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russian_phone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -17,13 +17,83 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.0.0
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
27
97
|
- !ruby/object:Gem::Dependency
|
28
98
|
name: bundler
|
29
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +123,7 @@ dependencies:
|
|
53
123
|
- !ruby/object:Gem::Version
|
54
124
|
version: '0'
|
55
125
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
126
|
+
name: simplecov
|
57
127
|
requirement: !ruby/object:Gem::Requirement
|
58
128
|
requirements:
|
59
129
|
- - ">="
|
@@ -67,7 +137,7 @@ dependencies:
|
|
67
137
|
- !ruby/object:Gem::Version
|
68
138
|
version: '0'
|
69
139
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
140
|
+
name: pry
|
71
141
|
requirement: !ruby/object:Gem::Requirement
|
72
142
|
requirements:
|
73
143
|
- - ">="
|
@@ -110,16 +180,19 @@ files:
|
|
110
180
|
- README.md
|
111
181
|
- Rakefile
|
112
182
|
- lib/russian_phone.rb
|
183
|
+
- lib/russian_phone/active_record.rb
|
113
184
|
- lib/russian_phone/codes.rb
|
114
185
|
- lib/russian_phone/field.rb
|
115
186
|
- lib/russian_phone/format_validator.rb
|
116
187
|
- lib/russian_phone/number.rb
|
117
188
|
- lib/russian_phone/presence_validator.rb
|
118
189
|
- lib/russian_phone/rails_admin.rb
|
190
|
+
- lib/russian_phone/railtie.rb
|
119
191
|
- lib/russian_phone/version.rb
|
120
192
|
- russian_phone.gemspec
|
121
193
|
- spec/phone_spec.rb
|
122
194
|
- spec/spec_helper.rb
|
195
|
+
- spec/support/ar_user.rb
|
123
196
|
- spec/support/mongoid.yml
|
124
197
|
- spec/support/user.rb
|
125
198
|
- spec/support/user_with_any_code.rb
|
@@ -152,6 +225,7 @@ summary: "Поле для хранения Российских телефонн
|
|
152
225
|
test_files:
|
153
226
|
- spec/phone_spec.rb
|
154
227
|
- spec/spec_helper.rb
|
228
|
+
- spec/support/ar_user.rb
|
155
229
|
- spec/support/mongoid.yml
|
156
230
|
- spec/support/user.rb
|
157
231
|
- spec/support/user_with_any_code.rb
|