russian_phone 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p374@russianphone --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in russian_phone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gleb Tv
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # RussianPhone
2
+
3
+ ## Что это
4
+
5
+ Гем для разбора и нормализации русских телефонных номеров
6
+
7
+ ## Внимание: гем находится в разработке и пока не готов для использования
8
+
9
+ ## Альтернативные решения
10
+
11
+ https://github.com/floere/phony
12
+
13
+ https://github.com/joost/phony_rails
14
+
15
+ https://github.com/carr/phone
16
+
17
+ Эти решения поддерживают несколько стран
18
+
19
+ russian_phone поддерживает и будет поддерживать только российские телефонные номера
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ gem 'russian_phone'
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install russian_phone
34
+
35
+ ## Usage
36
+
37
+ TODO: Write usage instructions here
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ require "russian_phone/version"
4
+
5
+ module RussianPhone
6
+ autoload :Field, 'russian_phone/field'
7
+ autoload :Number, 'russian_phone/number'
8
+ autoload :Codes, 'russian_phone/codes'
9
+ autoload :Validator, 'russian_phone/validator'
10
+
11
+ def self.field(options = {})
12
+ RussianPhone::Field.new(options)
13
+ end
14
+ end
@@ -0,0 +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
141
+ end
@@ -0,0 +1,42 @@
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::Validator, fields: [field.name]
14
+ end
15
+ end
16
+
17
+ # Get the object as it was stored in the database, and instantiate
18
+ # this custom class from it.
19
+ def demongoize(object)
20
+ RussianPhone::Number.new(object, @options)
21
+ end
22
+
23
+ # Takes any possible object and converts it to how it would be
24
+ # stored in the database.
25
+ def mongoize(object)
26
+ case object
27
+ when RussianPhone::Number then object.mongoize
28
+ when String then RussianPhone::Number.new(object, @options).mongoize
29
+ else object
30
+ end
31
+ end
32
+
33
+ # Converts the object that was supplied to a criteria and converts it
34
+ # into a database friendly form.
35
+ def evolve(object)
36
+ case object
37
+ when RussianPhone::Number then object.mongoize
38
+ else object
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,208 @@
1
+ # coding: utf-8
2
+
3
+ module RussianPhone
4
+ class Number
5
+ attr_accessor :phone, :options
6
+
7
+ def initialize(phone, options = {})
8
+ @options = self.class.process_options(options)
9
+ @phone = phone.to_s
10
+ end
11
+
12
+ def ==(other)
13
+ if other.class == self.class
14
+ # (other.phone == self.phone && other.options == self.options)
15
+ other.to_s == to_s
16
+ elsif other.class == String
17
+ parsed = RussianPhone::Number.new(other)
18
+ parsed.to_s == to_s
19
+ # parsed.phone == self.phone && parsed.options == self.options
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+ def coerce(something)
26
+ [self, something]
27
+ end
28
+
29
+ def parse(field)
30
+ data = self.class.parse(@phone, @options)
31
+ return nil if data.nil?
32
+
33
+ if data.has_key? :subscriber
34
+ @subscriber = data[:subscriber].to_s
35
+ @city = data[:city].to_s
36
+ @country = data[:country].to_s
37
+ end
38
+
39
+ data.has_key?(field) ? data[field] : nil
40
+ end
41
+
42
+ def valid?
43
+ @valid ||= !(country.nil? || city.nil? || subscriber.nil? || country == '' || city == '' || subscriber == '')
44
+ end
45
+
46
+ def subscriber
47
+ @subscriber ||= parse(:subscriber)
48
+ end
49
+
50
+ def city_allowed?
51
+ options[:allowed_cities].nil? || options[:allowed_cities].include?(city)
52
+ end
53
+
54
+ def city
55
+ @city ||= parse(:city)
56
+ end
57
+
58
+ def country
59
+ @country ||= parse(:country)
60
+ end
61
+
62
+ def split(format, number)
63
+ number = number.dup
64
+ format.inject([]) do |result, size|
65
+ result << number.slice!(0..size-1)
66
+ return result if number.empty?
67
+ result
68
+ end
69
+ end
70
+
71
+ def format
72
+ if subscriber.length == 7
73
+ split([3, 2, 2], subscriber)
74
+ elsif subscriber.length == 6
75
+ split([2, 2, 2], subscriber)
76
+ elsif subscriber.length == 5
77
+ split([1, 2, 2], subscriber)
78
+ else
79
+ []
80
+ end
81
+ end
82
+
83
+ def full
84
+ if valid?
85
+ if free?
86
+ "8-#{city}-#{format.join('-')}"
87
+ else
88
+ "+#{country} (#{city}) #{format.join('-')}"
89
+ end
90
+ else
91
+ ''
92
+ end
93
+ end
94
+
95
+ def clean
96
+ "#{country}#{city}#{subscriber}"
97
+ end
98
+
99
+ def cell?
100
+ Codes.cell_codes.include?(city)
101
+ end
102
+
103
+ def free?
104
+ city == '800'
105
+ end
106
+
107
+ # alias_method(:to_s, :full)
108
+ # alias_method(:inspect, :full)
109
+
110
+ def to_s
111
+ valid? ? full : @phone
112
+ end
113
+
114
+
115
+ def inspect
116
+ # '"' + full + '"'
117
+ '"' + to_s + '"'
118
+ end
119
+
120
+ #def mongoize
121
+ # valid? ? full : @phone
122
+ #end
123
+ alias_method(:mongoize, :to_s)
124
+
125
+ class << self
126
+ def clean(string)
127
+ string.tr('^0-9', '')
128
+ end
129
+
130
+ def _extract(string, subscriber_digits, code_digits)
131
+ [string[-(subscriber_digits + code_digits), code_digits], string[-subscriber_digits,subscriber_digits]]
132
+ end
133
+
134
+ def extract(string, subscriber_digits, code_digits)
135
+ _extract(clean(string), subscriber_digits, code_digits)
136
+ end
137
+
138
+ def country_code(string)
139
+ clean(string)[-10, 1]
140
+ end
141
+
142
+ def process_options(opts = {})
143
+ opts = {
144
+ default_country: 7,
145
+ default_city: nil,
146
+ allowed_cities: nil,
147
+ }.merge(opts)
148
+
149
+ opts[:default_country] = opts[:default_country].to_s unless opts[:default_country].nil?
150
+ opts[:default_city] = opts[:default_city].to_s unless opts[:default_city].nil?
151
+ opts[:allowed_cities] = opts[:allowed_cities].map { |c| c.to_s } unless opts[:allowed_cities].nil?
152
+
153
+ opts
154
+ end
155
+
156
+ def parse(string, opts = {})
157
+ return string if string.class.name == 'RussianPhone::Number'
158
+
159
+ opts = process_options(opts)
160
+
161
+ if string.class.name == 'Array'
162
+ string = string.join('')
163
+ else
164
+ string = string.to_s
165
+ end
166
+
167
+ clean_string = clean(string)
168
+
169
+ if clean_string.length > 11
170
+ return nil
171
+ end
172
+
173
+ if clean_string.length < 10
174
+ if opts[:default_city].nil?
175
+ return nil
176
+ elsif clean_string.length > 7
177
+ # Телефон слишком длинный для телефона без кода города
178
+ return nil
179
+ else
180
+ if Codes.codes_for(clean_string.length).include? opts[:default_city]
181
+ return {country: opts[:default_country], city: opts[:default_city], subscriber: clean_string}
182
+ else
183
+ # Количество цифр в телефоне не соответствует количеству цифр местных номеров города
184
+ return nil
185
+ end
186
+ end
187
+ end
188
+
189
+ code_3_digit, phone_7_digit = _extract(clean_string, 7, 3)
190
+ if code_3_digit == '800' || Codes.cell_codes.include?(code_3_digit) || Codes.ndcs_with_7_subscriber_digits.include?(code_3_digit)
191
+ return {country: opts[:default_country], city: code_3_digit, subscriber: phone_7_digit}
192
+ end
193
+
194
+ code_4_digit, phone_6_digit = _extract(clean_string, 6, 4)
195
+ if Codes.ndcs_with_6_subscriber_digits.include? code_4_digit
196
+ return {country: opts[:default_country], city: code_4_digit, subscriber: phone_6_digit}
197
+ end
198
+
199
+ code_5_digit, phone_5_digit = _extract(clean_string, 5, 5)
200
+ if Codes.ndcs_with_5_subscriber_digits.include? code_5_digit
201
+ return {country: opts[:default_country], city: code_5_digit, subscriber: phone_5_digit}
202
+ end
203
+
204
+ nil
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,11 @@
1
+ # coding: utf-8
2
+
3
+ module RussianPhone
4
+ class Validator < ActiveModel::Validator
5
+ def validate(record)
6
+ options[:fields].each do |field|
7
+ record.errors[field] << 'Неверный телефонный номер' unless record.send(field).valid? && record.send(field).city_allowed?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RussianPhone
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'russian_phone/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "russian_phone"
8
+ gem.version = RussianPhone::VERSION
9
+ gem.authors = ["GlebTv"]
10
+ gem.email = ["glebtv@gmail.com"]
11
+ gem.description = %q{Russian Phone Numbers for Mongoid}
12
+ gem.summary = %q{Поле для хранения Российских телефонных номеров в Mongoid}
13
+ gem.homepage = "https://github.com/glebtv/russian_phone"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+
21
+ gem.add_runtime_dependency(%q<mongoid>, [">= 2.4.0"])
22
+ gem.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
23
+ gem.add_development_dependency(%q<bundler>, [">= 1.1.0"])
24
+ gem.add_development_dependency(%q<simplecov>, [">= 0.4.0"])
25
+ gem.add_development_dependency(%q<database_cleaner>, ["~> 0.9.0"])
26
+ end
@@ -0,0 +1,326 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RussianPhone do
6
+ describe 'clean' do
7
+ it 'should remove everything except numbers from string' do
8
+ RussianPhone::Number.clean('+7 (906) 111-11-11').should eq '79061111111'
9
+ end
10
+ end
11
+
12
+ describe 'extract city' do
13
+ it 'should extract city from number correctly' do
14
+ RussianPhone::Number.extract('(906) 111-11-11', 7, 3).should eq ['906', '1111111']
15
+ RussianPhone::Number.extract('(906) 111-11-11', 6, 4).should eq ['9061', '111111']
16
+ RussianPhone::Number.extract('(906) 111-11-11', 5, 5).should eq ['90611', '11111']
17
+ end
18
+ end
19
+
20
+ describe 'when parsing' do
21
+ it 'should parse 8-800-111-11-11 number' do
22
+ phone = RussianPhone::Number.new('8-800-111-11-11', default_country: 7)
23
+ phone.should_not be_nil
24
+ phone.valid?.should be_true
25
+
26
+ phone.cell?.should be_false
27
+ phone.free?.should be_true
28
+
29
+ phone.city.should eq '800'
30
+ phone.country.should eq '7'
31
+ phone.subscriber.should eq '1111111'
32
+ phone.full.should eq '8-800-111-11-11'
33
+ end
34
+
35
+ it 'should parse (906) 111-11-11 number' do
36
+ phone = RussianPhone::Number.new('(906) 111-11-11', default_country: 7)
37
+ phone.should_not be_nil
38
+ phone.valid?.should be_true
39
+
40
+ phone.cell?.should be_true
41
+ phone.free?.should be_false
42
+
43
+ phone.city.should eq '906'
44
+ phone.country.should eq '7'
45
+ phone.subscriber.should eq '1111111'
46
+ phone.full.should eq '+7 (906) 111-11-11'
47
+ end
48
+
49
+ it 'should parse 111-11-11 number with default city' do
50
+ phone = RussianPhone::Number.new('111-11-11', default_country: 7, default_city: 495)
51
+ phone.should_not be_nil
52
+ phone.valid?.should be_true
53
+
54
+ phone.cell?.should be_false
55
+ phone.free?.should be_false
56
+
57
+ phone.city.should eq '495'
58
+ phone.country.should eq '7'
59
+ phone.subscriber.should eq '1111111'
60
+ phone.full.should eq '+7 (495) 111-11-11'
61
+ end
62
+
63
+ it 'should not parse 111-11-11 number without default city' do
64
+ phone = RussianPhone::Number.new('111-11-11', default_country: 7)
65
+ phone.valid?.should be_false
66
+ end
67
+
68
+ it 'should parse 1111111 number with default city' do
69
+ phone = RussianPhone::Number.new('1111111', default_country: 7, default_city: 495)
70
+ phone.should_not be_nil
71
+ phone.valid?.should be_true
72
+
73
+ phone.cell?.should be_false
74
+ phone.free?.should be_false
75
+
76
+ phone.city.should eq '495'
77
+ phone.country.should eq '7'
78
+ phone.subscriber.should eq '1111111'
79
+ phone.full.should eq '+7 (495) 111-11-11'
80
+ end
81
+
82
+ it 'should parse +7 (495) 111-11-11 number' do
83
+ phone = RussianPhone::Number.new('+7 (495) 111-11-11')
84
+ phone.should_not be_nil
85
+ phone.valid?.should be_true
86
+
87
+ phone.cell?.should be_false
88
+ phone.free?.should be_false
89
+
90
+ phone.city.should eq '495'
91
+ phone.country.should eq '7'
92
+ phone.subscriber.should eq '1111111'
93
+ phone.full.should eq '+7 (495) 111-11-11'
94
+ end
95
+
96
+ it 'should parse +7 (495) 111-11-11 number' do
97
+ phone = RussianPhone::Number.new('+7 (495) 111-11-11')
98
+ phone.should_not be_nil
99
+ phone.valid?.should be_true
100
+
101
+ phone.cell?.should be_false
102
+ phone.free?.should be_false
103
+
104
+ phone.city.should eq '495'
105
+ phone.country.should eq '7'
106
+ phone.subscriber.should eq '1111111'
107
+ phone.full.should eq '+7 (495) 111-11-11'
108
+ end
109
+
110
+ it 'should parse 8(4912)12-34-56 number' do
111
+ phone = RussianPhone::Number.new('+7 (4912) 12-34-56', default_country: 7)
112
+ phone.should_not be_nil
113
+ phone.valid?.should be_true
114
+
115
+ phone.cell?.should be_false
116
+ phone.free?.should be_false
117
+
118
+ phone.city.should eq '4912'
119
+ phone.country.should eq '7'
120
+ phone.subscriber.should eq '123456'
121
+ phone.full.should eq '+7 (4912) 12-34-56'
122
+ end
123
+
124
+ it 'should parse 12-34-56 number whith default city' do
125
+ phone = RussianPhone::Number.new('12-34-56', default_country: 7, default_city: 4912)
126
+ phone.should_not be_nil
127
+ phone.valid?.should be_true
128
+
129
+ phone.cell?.should be_false
130
+ phone.free?.should be_false
131
+
132
+ phone.city.should eq '4912'
133
+ phone.country.should eq '7'
134
+ phone.subscriber.should eq '123456'
135
+ phone.full.should eq '+7 (4912) 12-34-56'
136
+ end
137
+
138
+ it 'should parse 8(34356)5-67-89 number correctly' do
139
+ # это номер в Екатеринбурге, с неправильно указанным кодом города
140
+
141
+ phone = RussianPhone::Number.new('8(34356)5-67-89', default_country: 7)
142
+ phone.should_not be_nil
143
+ phone.valid?.should be_true
144
+
145
+ phone.cell?.should be_false
146
+ phone.free?.should be_false
147
+
148
+ phone.city.should eq '343'
149
+ phone.country.should eq '7'
150
+ phone.subscriber.should eq '5656789'
151
+ phone.full.should eq '+7 (343) 565-67-89'
152
+ end
153
+
154
+ tests = {
155
+ '+79261234567' => [7, 926, 1234567],
156
+ '89261234567' => [7, 926, 1234567],
157
+ '79261234567' => [7, 926, 1234567],
158
+ '+7 926 123 45 67' => [7, 926, 1234567],
159
+ '8(926)123-45-67' => [7, 926, 1234567],
160
+ '8 (926) 12-3-45-67' => [7, 926, 1234567],
161
+ '9261234567' => [7, 926, 1234567],
162
+ '(495)1234567' => [7, 495, 1234567],
163
+ '(495)123 45 67' => [7, 495, 1234567],
164
+ '8-926-123-45-67' => [7, 926, 1234567],
165
+ '8 927 1234 234' => [7, 927, 1234234],
166
+ '8 927 12 12 234' => [7, 927, 1212234],
167
+ '8 927 1 2 3 4 2 3 4' => [7, 927, 1234234],
168
+ '8 927 12 34 234' => [7, 927, 1234234],
169
+ '8 927 12 342 34' => [7, 927, 1234234],
170
+ '8 927 123-4-234' => [7, 927, 1234234],
171
+ '8 (927) 12 342 34' => [7, 927, 1234234],
172
+ '8-(927)-12-342-34' => [7, 927, 1234234],
173
+ '+7 927 1234 234' => [7, 927, 1234234],
174
+ '+7 927 12 12 234' => [7, 927, 1212234],
175
+ '+7 927 1 2 3 4 2 3 4' => [7, 927, 1234234],
176
+ '+7 927 12 34 234' => [7, 927, 1234234],
177
+ '+7 927 12 342 34' => [7, 927, 1234234],
178
+ '+7 927 123-4-234' => [7, 927, 1234234],
179
+ '+7 (927) 12 342 34' => [7, 927, 1234234],
180
+ '+7-(927)-12-342-34' => [7, 927, 1234234],
181
+ '7 927 1234 234' => [7, 927, 1234234],
182
+ '7 927 12 12 234' => [7, 927, 1212234],
183
+ '7 927 1 2 3 4 2 3 4' => [7, 927, 1234234],
184
+ '7 927 12 34 234' => [7, 927, 1234234],
185
+ '7 927 12 342 34' => [7, 927, 1234234],
186
+ '7 927 123-4-234' => [7, 927, 1234234],
187
+ '7 (927) 12 342 34' => [7, 927, 1234234],
188
+ '7-(927)-12-342-34' => [7, 927, 1234234],
189
+ '7 84543 123 12' => [7, 84543, 12312],
190
+ }
191
+
192
+ tests.each_pair do |str, result|
193
+ it "should parse #{str}" do
194
+ phone = RussianPhone::Number.new(str, default_country: 7)
195
+ phone.should_not be_nil
196
+ phone.valid?.should be_true
197
+
198
+ if %w(927 926).include? result[1].to_s
199
+ phone.cell?.should be_true
200
+ else
201
+ phone.cell?.should be_false
202
+ end
203
+
204
+ phone.free?.should be_false
205
+
206
+ phone.country.should eq result[0].to_s
207
+ phone.city.should eq result[1].to_s
208
+ phone.subscriber.should eq result[2].to_s
209
+ phone.clean.should eq "#{result[0]}#{result[1]}#{result[2]}"
210
+ end
211
+ end
212
+
213
+ bad_phones = [
214
+ '123 123',
215
+ '11 11 11 11 11 11 11',
216
+ '123',
217
+ 'пыщ пыщ ололо я водитель НЛО',
218
+ '11 11 11 11 1'
219
+ ]
220
+
221
+ bad_phones.each do |phone|
222
+ it "should not parse #{phone}" do
223
+ phone = RussianPhone::Number.new(phone, default_country: 7)
224
+ phone.valid?.should be_false
225
+ end
226
+ end
227
+ end
228
+
229
+ describe 'when using ::Field' do
230
+ it 'should serialize and deserialize correctly' do
231
+ RussianPhone::Number.new('495 111 11 11').mongoize.should eq '+7 (495) 111-11-11'
232
+ RussianPhone::Number.demongoize('+7 (495) 111-11-11').mongoize.should eq '+7 (495) 111-11-11'
233
+ end
234
+ end
235
+
236
+ describe 'when storing with mongoid' do
237
+ it 'should parse, store and retrieve numbers correctly' do
238
+ u = User.new(name: 'test', phone: '906 111 11 11')
239
+ u.save.should be_true
240
+ u = User.first
241
+
242
+ u.phone.should eq '+7 (906) 111-11-11'
243
+ u.phone.cell?.should be_true
244
+ u.phone.free?.should be_false
245
+
246
+ u.phone.clean.should eq '79061111111'
247
+
248
+ u.phone.country.should eq '7'
249
+ u.phone.city.should eq '906'
250
+ u.phone.subscriber.should eq '1111111'
251
+ end
252
+
253
+ it 'should respect field options' do
254
+ u = User.create(name: 'test', phone_in_495: '111 11 11', phone_in_812: '222 2222')
255
+ u.save.should be_true
256
+
257
+ u = User.first
258
+
259
+ u.phone_in_495.class.name.should eq 'RussianPhone::Number'
260
+ u.phone_in_495.should eq '+7 (495) 111-11-11'
261
+ u.phone_in_495.cell?.should be_false
262
+ u.phone_in_495.free?.should be_false
263
+
264
+ u.phone_in_495.country.should eq '7'
265
+ u.phone_in_495.city.should eq '495'
266
+ u.phone_in_495.subscriber.should eq '1111111'
267
+
268
+ u.phone_in_495.clean.should eq '74951111111'
269
+ u.phone_in_495.full.should eq '+7 (495) 111-11-11'
270
+
271
+ u.phone_in_812.class.name.should eq 'RussianPhone::Number'
272
+ u.phone_in_812.should eq '+7 (812) 222-22-22'
273
+ u.phone_in_812.cell?.should be_false
274
+ u.phone_in_812.free?.should be_false
275
+
276
+ u.phone_in_812.country.should eq '7'
277
+ u.phone_in_812.city.should eq '812'
278
+ u.phone_in_812.subscriber.should eq '2222222'
279
+
280
+ u.phone_in_812.clean.should eq '78122222222'
281
+ u.phone_in_812.full.should eq '+7 (812) 222-22-22'
282
+ end
283
+
284
+ it 'should fail validation when validate is on and phone is invalid' do
285
+ u = UserWithValidation.new(phone: '123')
286
+ u.valid?.should be_false
287
+ u.save.should be_false
288
+ u.errors.messages.should eq({:phone =>["Неверный телефонный номер"]})
289
+ end
290
+
291
+ it 'should pass validation when validate is on and phone is valid' do
292
+ u = UserWithValidation.new(phone: '495 121 11 11')
293
+ u.valid?.should be_true
294
+ u.save.should be_true
295
+ end
296
+
297
+ it 'should fail validation when validate is on and city is not in allowed_cities' do
298
+ u = UserWithValidation.new(phone: '906 121 11 11')
299
+ u.valid?.should be_false
300
+ u.save.should be_false
301
+ u.errors.messages.should eq({:phone =>["Неверный телефонный номер"]})
302
+ end
303
+
304
+ it 'should pass validation when validate is off and phone is invalid' do
305
+ u = UserWithoutValidation.new(phone: '123')
306
+
307
+ u.valid?.should be_true
308
+ u.save.should be_true
309
+ end
310
+
311
+ it 'should pass validation when validate is off and phone is valid' do
312
+ u = UserWithoutValidation.new(phone: '495 121 11 11')
313
+
314
+ u.valid?.should be_true
315
+ u.save.should be_true
316
+ end
317
+
318
+ it 'should pass validation when validate is off and city is not in allowed_cities' do
319
+ u = UserWithoutValidation.new(phone: '906 121 11 11')
320
+
321
+ u.valid?.should be_true
322
+ u.save.should be_true
323
+ end
324
+ end
325
+
326
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ require 'rspec'
6
+ require 'simplecov'
7
+ require 'mongoid'
8
+
9
+ require 'database_cleaner'
10
+
11
+ SimpleCov.start
12
+
13
+ require 'russian_phone'
14
+
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
+ def mongoid3?
20
+ defined?(Mongoid::VERSION) && Gem::Version.new(Mongoid::VERSION) >= Gem::Version.new('3.0.0')
21
+ end
22
+
23
+ Mongoid.configure do |config|
24
+ if mongoid3?
25
+ config.sessions[:default] = { :database => 'russian_phone_test', :hosts => ['localhost:27017'] }
26
+ else
27
+ config.master = Mongo::Connection.new.db('russian_phone_test')
28
+ end
29
+ end
30
+
31
+ DatabaseCleaner.orm = "mongoid"
32
+
33
+ RSpec.configure do |config|
34
+ config.before(:all) do
35
+ DatabaseCleaner.strategy = :truncation
36
+ end
37
+
38
+ config.before(:each) do
39
+ DatabaseCleaner.start
40
+ end
41
+
42
+ config.after(:each) do
43
+ DatabaseCleaner.clean
44
+ end
45
+
46
+ config.mock_with :rspec
47
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ class User
4
+ include Mongoid::Document
5
+
6
+ field :name
7
+
8
+ field :phone, type: RussianPhone.field(default_country: 7, allowed_cities: [495])
9
+
10
+ field :phone_in_495, type: RussianPhone.field(default_country: 7, default_city: '495')
11
+ field :phone_in_812, type: RussianPhone.field(default_country: 7, default_city: '812')
12
+ end
@@ -0,0 +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
7
+ end
@@ -0,0 +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
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: russian_phone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GlebTv
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.4.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: database_cleaner
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.9.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.9.0
94
+ description: Russian Phone Numbers for Mongoid
95
+ email:
96
+ - glebtv@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rvmrc
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - lib/russian_phone.rb
108
+ - lib/russian_phone/codes.rb
109
+ - lib/russian_phone/field.rb
110
+ - lib/russian_phone/number.rb
111
+ - lib/russian_phone/validator.rb
112
+ - lib/russian_phone/version.rb
113
+ - russian_phone.gemspec
114
+ - spec/phone_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/user.rb
117
+ - spec/support/user_with_validation.rb
118
+ - spec/support/user_without_validation.rb
119
+ homepage: https://github.com/glebtv/russian_phone
120
+ licenses: []
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.25
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Поле для хранения Российских телефонных номеров в Mongoid
143
+ test_files:
144
+ - spec/phone_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/user.rb
147
+ - spec/support/user_with_validation.rb
148
+ - spec/support/user_without_validation.rb