ptc 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4f3cfad480259d997a156029f7ec8a69e0e0a5ba5ffed319b88b39070435af7d
4
+ data.tar.gz: 4106345af88254378a9f9fca698f6c45f494098584a4af7f72b784071862f260
5
+ SHA512:
6
+ metadata.gz: f6e47e519fd41f604c18658b245d86955e783d248e29664afb6efb10afcb25671f11f2872386a6b611eb7a7b99afd3ef11b597a911b7cfcc39d88ca20a12a84c
7
+ data.tar.gz: 1da9097ee6f91bfbf4aee1c772480ee3d3071372e3f23d429ea5e54e481ec646daeca18af1215c4fb1a0c9f983fc4c05931bfab64e3943b772f8e25d1ace0b31
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --require spec_helper
2
+ --color
3
+ --format progress
4
+ --order rand
@@ -0,0 +1,50 @@
1
+ Style/AsciiComments:
2
+ Description: 'Use only ascii symbols in comments.'
3
+ StyleGuide: '#english-comments'
4
+ Enabled: false
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Style/CommentedKeyword:
8
+ Enabled: false
9
+ Style/SymbolArray:
10
+ Enabled: false
11
+ Metrics/LineLength:
12
+ Max: 120
13
+ Enabled: false
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+ Metrics/ModuleLength:
17
+ Enabled: false
18
+ Metrics/ParameterLists:
19
+ Max: 3
20
+ CountKeywordArgs: true
21
+ Layout/LeadingCommentSpace:
22
+ Enabled: false
23
+ Layout/SpaceBeforeComment:
24
+ Enabled: false
25
+ Layout/ExtraSpacing:
26
+ Enabled: false
27
+ Layout/CaseIndentation:
28
+ Enabled: false
29
+ Layout/SpaceAroundOperators:
30
+ Enabled: false
31
+ Style/FormatString:
32
+ Enabled: false
33
+ Style/FormatStringToken:
34
+ Enabled: false
35
+ Layout/AlignParameters:
36
+ Enabled: false
37
+ Metrics/BlockNesting:
38
+ Enabled: false
39
+ Layout/TrailingWhitespace:
40
+ Enabled: false
41
+ Metrics/AbcSize:
42
+ Enabled: false
43
+ Style/Documentation:
44
+ Enabled: false
45
+ Layout/AlignHash:
46
+ Enabled: false
47
+ Metrics/ClassLength:
48
+ Enabled: false
49
+ Lint/Syntax:
50
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ptc.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem 'guard-rspec'
10
+ gem 'rspec'
11
+ gem 'byebug'
12
+ end
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ptc (0.1.0)
5
+ countries (~> 1.2.0)
6
+ phony (> 2.15)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (11.1.3)
12
+ coderay (1.1.2)
13
+ countries (1.2.5)
14
+ currencies (~> 0.4.2)
15
+ i18n_data (~> 0.7.0)
16
+ currencies (0.4.2)
17
+ diff-lcs (1.3)
18
+ ffi (1.11.1)
19
+ formatador (0.2.5)
20
+ guard (2.16.2)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 2.7, < 4.0)
23
+ lumberjack (>= 1.0.12, < 2.0)
24
+ nenv (~> 0.1)
25
+ notiffany (~> 0.0)
26
+ pry (>= 0.9.12)
27
+ shellany (~> 0.0)
28
+ thor (>= 0.18.1)
29
+ guard-compat (1.2.1)
30
+ guard-rspec (4.7.3)
31
+ guard (~> 2.1)
32
+ guard-compat (~> 1.1)
33
+ rspec (>= 2.99.0, < 4.0)
34
+ i18n_data (0.7.0)
35
+ listen (3.1.5)
36
+ rb-fsevent (~> 0.9, >= 0.9.4)
37
+ rb-inotify (~> 0.9, >= 0.9.7)
38
+ ruby_dep (~> 1.2)
39
+ lumberjack (1.2.5)
40
+ method_source (0.9.2)
41
+ nenv (0.3.0)
42
+ notiffany (0.1.3)
43
+ nenv (~> 0.1)
44
+ shellany (~> 0.0)
45
+ phony (2.18.15)
46
+ pry (0.12.2)
47
+ coderay (~> 1.1.0)
48
+ method_source (~> 0.9.0)
49
+ rake (13.0.1)
50
+ rb-fsevent (0.10.3)
51
+ rb-inotify (0.10.0)
52
+ ffi (~> 1.0)
53
+ rspec (3.8.0)
54
+ rspec-core (~> 3.8.0)
55
+ rspec-expectations (~> 3.8.0)
56
+ rspec-mocks (~> 3.8.0)
57
+ rspec-core (3.8.2)
58
+ rspec-support (~> 3.8.0)
59
+ rspec-expectations (3.8.4)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.8.0)
62
+ rspec-mocks (3.8.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.8.0)
65
+ rspec-support (3.8.2)
66
+ ruby_dep (1.5.0)
67
+ shellany (0.0.1)
68
+ thor (0.20.3)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler
75
+ byebug
76
+ guard-rspec
77
+ ptc!
78
+ rake
79
+ rspec
80
+
81
+ BUNDLED WITH
82
+ 2.1.4
@@ -0,0 +1,15 @@
1
+ guard :rspec, cmd: "rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ end
@@ -0,0 +1 @@
1
+ `get_country_geo_by_phone(phone_number)` -- Получить геометрический (географический) центр страны по номеру телефона
@@ -0,0 +1,13 @@
1
+ RELEASING
2
+ =========
3
+
4
+ Needed:
5
+ $ gem install gem-release
6
+
7
+ Steps:
8
+ 0. bundle config local.ptc /home/<user>/git/my/ruby/ptc/
9
+ 1. bundle exec rspec
10
+ 2. ptc/version.rb - increase version
11
+ 3. history.textile - add a new entry on top with the version. Describe and give thanks!
12
+ 4. build (RubyMine: <alt>+<t>, <alt>+<g>, <alt>+<b>)
13
+ 5. push (RubyMine: <alt>+<t>, <alt>+<g>, <alt>+<p>)
@@ -0,0 +1,16 @@
1
+ # Specs.
2
+ #
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ # desc 'Run specs'
7
+ # RSpec::Core::RakeTask.new :spec do |t|
8
+ # t.ruby_opts = ['-w']
9
+ # end
10
+ task :spec do |t|
11
+ puts 'Running RSpec'
12
+ system 'rspec'
13
+ puts
14
+ end
15
+
16
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ h2. Version 1.0.0
2
+
3
+ * First release
@@ -0,0 +1,15 @@
1
+ require 'ostruct'
2
+ require 'phony'
3
+ require 'countries'
4
+
5
+ # загружаем библиотечные классы
6
+ lambda do
7
+ %w[../ptc/utils ../ptc].each do |path|
8
+ lib_path = '%s/**/*.rb' % File.expand_path(path, __FILE__)
9
+ # noinspection RubyResolve
10
+ Dir[lib_path].each { |f| require_relative f }
11
+ end
12
+ end.call
13
+
14
+ module Ptc
15
+ end
@@ -0,0 +1,19 @@
1
+ countries_priorities:
2
+ 1:
3
+ - US
4
+ - CA
5
+ - DO
6
+ - PR
7
+ 7:
8
+ - RU
9
+ - KZ
10
+ 39:
11
+ - IT
12
+ - VA
13
+ 590:
14
+ - GP
15
+ - BL
16
+ - MF
17
+ 599:
18
+ - BQ
19
+ - CW
@@ -0,0 +1,35 @@
1
+ module GetCountryByPhone
2
+ include Numer
3
+ include CountriesPriorities
4
+
5
+ # Получить геометрический (географический) центр страны по номеру телефона
6
+ # Если коду страны из номера телефона соответствуют более 1 страны (например, +7 для RU и KZ),
7
+ # то взята будет одна первая страна из списка согласно приоритету +countries_priorities.yml+
8
+ def get_country_geo_by_phone(phone_number)
9
+ return nil if phone_number.nil?
10
+
11
+ phone_number = Phony.split(_numeric phone_number)
12
+ return nil unless phone_number.all?
13
+
14
+ country_code = phone_number[0]
15
+ countries = ISO3166::Country.find_all_by(:country_code, country_code)
16
+ top_country = top_priority_country_by_country_code country_code
17
+ country = top_country.nil? ? countries.values.first : countries[top_country]
18
+
19
+ #gem "countries", '3.0.1'
20
+ #country_geo = country.values.first['geo']
21
+ # OpenStruct.new(
22
+ # latitude: country_geo['latitude'],
23
+ # longitude: country_geo['longitude']
24
+ # )
25
+
26
+ #puts [country['latitude_dec'], country['longitude_dec']].join ','
27
+ OpenStruct.new(
28
+ latitude: country['latitude_dec'],
29
+ longitude: country['longitude_dec']
30
+ )
31
+ rescue ::Phony::SplittingError
32
+ nil
33
+ end
34
+
35
+ end
@@ -0,0 +1,13 @@
1
+ module CountriesPriorities
2
+ def top_priority_country_by_country_code(country_code)
3
+ cp = cps[country_code.to_i]
4
+ cp&.first
5
+ end
6
+
7
+ def cps
8
+ @_dict ||= begin
9
+ ppp = File.expand_path '../dicts/countries_priorities.yml', File.dirname(__FILE__)
10
+ YAML.load_file(ppp)['countries_priorities']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module Numer
2
+ DIGIT = /\d/
3
+ def _numeric(str)
4
+ str.scan(DIGIT).join
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Ptc
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ptc/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ptc"
7
+ spec.version = Ptc::VERSION
8
+ spec.authors = ["TZ"]
9
+ spec.email = ["t.zozulya@key-g.com"]
10
+
11
+ spec.summary = %q{GEO+PHONES}
12
+ spec.homepage = "http://getboat.com"
13
+ spec.license = 'MIT'
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_dependency 'phony', '> 2.15'
27
+ spec.add_dependency 'countries', '~> 1.2.0'
28
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ptc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - TZ
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: phony
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.15'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: countries
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ description:
70
+ email:
71
+ - t.zozulya@key-g.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - Guardfile
82
+ - README.md
83
+ - RELEASING.txt
84
+ - Rakefile
85
+ - history.textile
86
+ - lib/ptc.rb
87
+ - lib/ptc/dicts/countries_priorities.yml
88
+ - lib/ptc/get_country_by_phone.rb
89
+ - lib/ptc/utils/countries_priorities.rb
90
+ - lib/ptc/utils/numer.rb
91
+ - lib/ptc/version.rb
92
+ - ptc.gemspec
93
+ homepage: http://getboat.com
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: GEO+PHONES
116
+ test_files: []