DKRdecode 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 807e1664108d9533cbeea5343c35805283bc79efb6deb9f25c187b3fb6dac80b
4
+ data.tar.gz: 9e5335c263b7a42794f02200501049652440f0c31bac3e3b6dfb7b34945772de
5
+ SHA512:
6
+ metadata.gz: 3a1548a2c9043d35eac299f36a34b70a7b72a6800c3c8300aaa110229cdabfa9c55ca2a28d65ec290faf8a1b59ea094dee95dfcb3a6641a019a25b80c68dae0a
7
+ data.tar.gz: cd303e5dcc8767da74d4cb2781f2cb4bbc8242442bb154e7e08b6eb6a4dca7c11bce711d2dc1bad140303b922fcac0f3ed3795a48e4fa51bcad3f8b0a4394c9a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
File without changes
data/DKRdecode.gemspec ADDED
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "DKRdecode/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "DKRdecode"
8
+ spec.version = DKRdecode::VERSION
9
+ spec.authors = ["vesh95"]
10
+ spec.email = ["vesh95.17@gmail.com"]
11
+
12
+ spec.summary = "Гем для расшифровки результатов ДКР"
13
+ spec.description = ""
14
+ spec.homepage = "https://github.com/vesh95/DKRdecode"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/vesh95/DKRdecode"
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ end
data/Gemfile ADDED
@@ -0,0 +1,10 @@
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 DKRdecode.gemspec
6
+ gemspec
7
+
8
+ gem "sequel"
9
+ gem "spreadsheet"
10
+ gem "sqlite3"
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ DKRdecode (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+ ruby-ole (1.2.12.1)
11
+ sequel (5.15.0)
12
+ spreadsheet (1.1.8)
13
+ ruby-ole (>= 1.0)
14
+ sqlite3 (1.3.13)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ DKRdecode!
21
+ bundler (~> 1.16)
22
+ rake (~> 10.0)
23
+ sequel
24
+ spreadsheet
25
+ sqlite3
26
+
27
+ BUNDLED WITH
28
+ 1.16.6
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # DKRdecode
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/DKRdecode`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'DKRdecode'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install DKRdecode
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/DKRdecode.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "DKRdecode"
5
+ require "optparse"
6
+ require "irb"
7
+
8
+ IRB.start(__FILE__)
data/bin/dkrdecode ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "DKRdecode"
5
+ require "optparse"
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = 'Usage: dkrdecode <params> [options]'
10
+
11
+ opts.on('-v', '--version', 'Prints version') do
12
+ puts "dkrdecode v#{DKRdecode::VERSION}"
13
+ exit
14
+ end
15
+
16
+ opts.on('-V', '--verbose', 'Displays information about all actions.') do
17
+ options['verbose'] = true
18
+ end
19
+
20
+ opts.on('-h', '--help', 'Print this help') do
21
+ puts opts
22
+ exit
23
+ end
24
+
25
+ opts.on('-ixls', '--input=xls', 'Input .xls file.') do |xls|
26
+ options['xls'] = xls
27
+ end
28
+ end.parse!
29
+
30
+ if ARGV.include?('migrate')
31
+ DKRdecode::Database.migrate(options)
32
+ end
33
+
34
+ if ARGV.include?('decode')
35
+ DKRdecode::Decode.run(options)
36
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ module DKRdecode
2
+ ##
3
+ # Этот класс предоставляет методы мограции
4
+ class Database
5
+ require 'sequel'
6
+ require_relative 'migrations/migration'
7
+
8
+ # Создает недостающие директории и файлы и проводит миграции
9
+ def self.migrate(exclusive_params)
10
+ while true
11
+ if File.directory? ENV['path']
12
+ if File.exist?("#{ENV['path']}/db.sqlite")
13
+ $stderr.puts "db.sqlite is exists. Migrating..."
14
+ return DKRdecode::Migration.migrate(DKRdecode::DB)
15
+ else
16
+ $stderr.puts "Creating file: #{ENV['path']}/db.sqlite"
17
+ File.open("#{ENV['path']}/db.sqlite", 'w')
18
+ end
19
+ # File.exist?
20
+ else
21
+ $stderr.puts "Creating dir: #{ENV['path']}"
22
+ Dir.mkdir(ENV['path'])
23
+ end
24
+ # File.directory?
25
+ end
26
+ # whil
27
+ exit 0
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ module DKRdecode
2
+ ##
3
+ # Этот класс предоставляет методы для расшифровки кодов ДКР
4
+ class Decode
5
+ require 'spreadsheet'
6
+ ##
7
+ # Запускает расшифровку
8
+ # @param options параметры, переданные из командной строки
9
+ def self.run (options)
10
+ peoples = DKRdecode::DB[:peoples].all
11
+ Spreadsheet.client_encoding = 'UTF-8'
12
+ book = Spreadsheet.open options['xls']
13
+ book.worksheet(0).each 1 do |row|
14
+ val = peoples.detect{ |yey| yey[:code]==row[8].to_i }
15
+ unless val.nil?
16
+ row[8] = val[:name]
17
+ end
18
+ end
19
+
20
+ book.write '~/out.xls'
21
+ exit 0
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module DKRdecode
2
+ ##
3
+ # Содержит миграции
4
+ class Migration
5
+ # Проведения миграций над базой данных
6
+ def self.migrate(db)
7
+ begin
8
+ db.create_table :peoples do
9
+ primary_key :id
10
+ String :name
11
+ Integer :code
12
+ end
13
+ return db
14
+ rescue Sequel::DatabaseError
15
+ $stderr.puts 'Table `peoples` already exists'
16
+ exit 1
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module DKRdecode
2
+ # Содержит номер текущей версии
3
+ VERSION = "0.1.0"
4
+ end
data/lib/DKRdecode.rb ADDED
@@ -0,0 +1,16 @@
1
+ ##
2
+ # Расшифровка результатов ДКР
3
+ module DKRdecode
4
+ require "DKRdecode/version"
5
+ require "DKRdecode/database"
6
+ require "DKRdecode/decode"
7
+
8
+ ENV['path'] = Dir.home + "/.dkrdecode"
9
+ ENV['database_path'] = "#{ENV['path']}/db.sqlite"
10
+ begin
11
+ # Содержит данные доступа к БД
12
+ DB = Sequel.sqlite(ENV['database_path'])
13
+ rescue
14
+ $stderr.puts "База не существует, запустите dkrdecode migrate"
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: DKRdecode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - vesh95
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-05 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: ''
42
+ email:
43
+ - vesh95.17@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - DKRdecode.gemspec
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/dkrdecode
57
+ - bin/setup
58
+ - lib/DKRdecode.rb
59
+ - lib/DKRdecode/database.rb
60
+ - lib/DKRdecode/decode.rb
61
+ - lib/DKRdecode/migrations/migration.rb
62
+ - lib/DKRdecode/version.rb
63
+ homepage: https://github.com/vesh95/DKRdecode
64
+ licenses: []
65
+ metadata:
66
+ homepage_uri: https://github.com/vesh95/DKRdecode
67
+ source_code_uri: https://github.com/vesh95/DKRdecode
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.7.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Гем для расшифровки результатов ДКР
88
+ test_files: []