find_max 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f0f2754393ada65aa01886ab9c123d00f045541
4
+ data.tar.gz: 4a6c799bbd94e1f52d0a4ddaee2e09e02c1840a9
5
+ SHA512:
6
+ metadata.gz: 413fe988dc42646268883520ce7b206c2021b5b361cea6752785719f57308656fb05b9ad84d2111be74f446e05da11ca3341d02b06ac86b64b51d1b25265869e
7
+ data.tar.gz: c4b28a40f9618b7a08104e967f84e1d27e654c110f8903ff08958c604900e66aacdc8a5f7711dfc53916ea7bf7acdc4666950f320e62151a014c6d815737dbe1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .idea
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ bundler_args: --jobs=2
6
+ script:
7
+ - bundle exec rspec
8
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at Genom-1990@yandex.ru. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in find_max.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FindMax
2
+
3
+ [![Build Status](https://travis-ci.org/Rattt/find_max.svg?branch=master)](https://travis-ci.org/Rattt/find_max)
4
+ **FindMax**
5
+
6
+ ## Common description
7
+
8
+ The application is console.
9
+ The library receives a stream of numbers and quantity of the maximum numbers for search.
10
+ Besides amount of enrollment of numbers very big.
11
+
12
+
13
+ ## Installing
14
+
15
+ ```ruby
16
+ gem install 'find_max'
17
+ ```
18
+ Installation is finished!
19
+
20
+
21
+ ## Usage
22
+
23
+ `Use: cat some_file.txt | nmax Number`
24
+
25
+ Or
26
+
27
+ ` "echo 'numbers' | nmax Number"`
28
+
29
+ ## Thanks for watching
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => :spec
data/bin/nmax ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'colorize'
5
+ require 'i18n'
6
+ require 'optparse'
7
+ require 'find_max'
8
+
9
+ FindMax::Cli.new(ARGV).execute
data/find_max.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'find_max/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "find_max"
8
+ spec.version = FindMax::VERSION
9
+ spec.authors = ["Rustam Safin"]
10
+ spec.email = ["Genom-1990@yandex.ru"]
11
+
12
+ spec.summary = %q{}
13
+ spec.description = %q{ find max numbers from file}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'immutable-ruby', '0.0.1'
25
+ spec.add_dependency 'i18n', '0.7.0'
26
+ spec.add_dependency 'colorize', '0.8.1'
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.13"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+
31
+ spec.add_development_dependency 'rspec', '3.5.0'
32
+ spec.add_development_dependency 'rspec-command', '1.0.1'
33
+
34
+ end
@@ -0,0 +1,64 @@
1
+ module FindMax
2
+
3
+ class Cli
4
+
5
+ include FindMax::Modules::CheckTypes
6
+ include FindMax::Modules::Info
7
+
8
+ AVAILABLE_MODES = ['command', 'help', 'version']
9
+
10
+ def initialize(argv)
11
+ @argv = argv
12
+ end
13
+
14
+ def execute
15
+
16
+ mode = AVAILABLE_MODES[0]
17
+ OptionParser.new do |opts|
18
+ opts.banner = I18n.t 'help.use_the_sample'
19
+ opts.separator I18n.t 'help.description'
20
+ opts.on_tail("-h", "--help", I18n.t('help.about_help')) do
21
+ mode = AVAILABLE_MODES[1]
22
+ info(opts.to_s)
23
+ end
24
+ opts.on_tail("-v", "--version", I18n.t('help.version_gem')) do
25
+ mode = AVAILABLE_MODES[1]
26
+ info(FindMax::VERSION)
27
+ end
28
+ opts.parse!
29
+ end
30
+
31
+ if mode == AVAILABLE_MODES[0]
32
+ result(command)
33
+ end
34
+
35
+ rescue ArgumentError => e
36
+ error_message(e.message + "\n" + I18n.t('help.need_help'))
37
+ rescue Exception => e
38
+ error_message(e.message)
39
+ end
40
+
41
+ private
42
+
43
+ def command
44
+
45
+ if $stdin.tty?
46
+ raise ArgumentError, I18n.t('error.argument.empty_file')
47
+ end
48
+ if @argv.length > 1
49
+ raise ArgumentError, I18n.t('error.argument.unknown_arguments')
50
+ end
51
+ if @argv.empty?
52
+ raise ArgumentError, I18n.t('error.argument.empty_max_number')
53
+ end
54
+
55
+ unless self.is_number?(@argv[0])
56
+ raise ArgumentError, I18n.t('error.argument.incorrect_max_number')
57
+ end
58
+
59
+ @count_max_numbers = @argv[0].to_i
60
+ FindMax::Services::FindMaxNumbers.new(@count_max_numbers).execute
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+
2
+ I18n.load_path += Dir[File.join(File.expand_path('../../', __FILE__), 'locales', '*.yml').to_s]
3
+ I18n.default_locale = :en
@@ -0,0 +1,18 @@
1
+ en:
2
+ help:
3
+ about_help: I show a way of start of team of search
4
+ need_help: (-h or --help shows available options for use)
5
+ use_the_sample: 'Use: cat some_file.txt | nmax Number'
6
+ description: The program finds from file N of the largest numbers.
7
+ version_gem: Version of gem
8
+
9
+ error:
10
+ argument:
11
+ empty_file: The stream with numbers isn't provided.
12
+ empty_max_number: The quantity the makismalnykh of numbers isn't established.
13
+ unknown_arguments: The bigger quantity of arguments has been sent to an entrance, than it was expected.
14
+ incorrect_max_number: On an entrance not the number has arrived.
15
+
16
+ result:
17
+ title: 'Result of calculations:'
18
+
@@ -0,0 +1,9 @@
1
+ module FindMax::Modules
2
+ module CheckTypes
3
+
4
+ def is_number?(obj)
5
+ obj.to_s == obj.to_i.to_s
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module FindMax::Modules
2
+
3
+ module Info
4
+
5
+ def error_message(message)
6
+ $stderr.puts message.colorize(:red)
7
+ end
8
+
9
+ def info(message)
10
+ puts message.colorize(:blue)
11
+ end
12
+
13
+ def result(arr)
14
+ puts I18n.t('result.title').colorize(:green)
15
+ puts arr.to_s.colorize(:green)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,69 @@
1
+ module FindMax::Services
2
+
3
+ class FindMaxNumbers
4
+
5
+ include FindMax::Modules::Info
6
+
7
+ def initialize(count_max_numbers)
8
+ @count_max_numbers = count_max_numbers
9
+ @count_max_numbers_negative = -(@count_max_numbers)
10
+ end
11
+
12
+ def execute
13
+
14
+ if $stdin.tty?
15
+ return nil
16
+ end
17
+
18
+ @sets_max_numbers = Immutable::SortedSet.new
19
+ numbers = []
20
+ length = 0
21
+ $stdin.each_line do |line|
22
+ numbers = line.scan(/\d+/).map { |i| i.to_i } || []
23
+
24
+ add_to_set_numbers(numbers, length)
25
+
26
+ length = @sets_max_numbers.length
27
+ if (@count_max_numbers < length)
28
+ @sets_max_numbers = @sets_max_numbers[@count_max_numbers_negative..-1]
29
+ end
30
+ end
31
+
32
+ @sets_max_numbers.to_a
33
+ rescue Exception => e
34
+ error_message(e.message)
35
+ return nil
36
+ end
37
+
38
+ private
39
+
40
+ def add_to_set_numbers(numbers, length)
41
+ current_increase = 0
42
+ is_min_namber_isset = !@sets_max_numbers.min.nil?
43
+ is_minimum_set_of_full = @count_max_numbers < length + current_increase + 1
44
+
45
+ if is_min_namber_isset && is_minimum_set_of_full
46
+ min_number = @sets_max_numbers.min
47
+ numbers.each do |number|
48
+ next if min_number > number
49
+ @sets_max_numbers = @sets_max_numbers << number
50
+ min_number = @sets_max_numbers.min
51
+ current_increase += 1
52
+ end
53
+ else
54
+ min_number = @sets_max_numbers.min
55
+ numbers.each do |number|
56
+ is_big_number = min_number > number rescue false
57
+ if is_big_number
58
+ next unless @count_max_numbers > length + current_increase
59
+ end
60
+ @sets_max_numbers = @sets_max_numbers << number
61
+ min_number = @sets_max_numbers.min
62
+ current_increase += 1
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,3 @@
1
+ module FindMax
2
+ VERSION = "1.2.1"
3
+ end
data/lib/find_max.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'find_max/version'
2
+ require 'find_max/modules/check_types'
3
+ require 'find_max/modules/info'
4
+ require 'immutable/sorted_set'
5
+ require 'find_max/services/find_max_numbers'
6
+ require 'find_max/cli'
7
+ require 'find_max/initialize/i18n'
8
+
9
+ module FindMax
10
+ # Your code goes here...
11
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: find_max
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Rustam Safin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: immutable-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-command
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.1
111
+ description: " find max numbers from file"
112
+ email:
113
+ - Genom-1990@yandex.ru
114
+ executables:
115
+ - nmax
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/nmax
128
+ - find_max.gemspec
129
+ - lib/find_max.rb
130
+ - lib/find_max/cli.rb
131
+ - lib/find_max/initialize/i18n.rb
132
+ - lib/find_max/locales/en.yml
133
+ - lib/find_max/modules/check_types.rb
134
+ - lib/find_max/modules/info.rb
135
+ - lib/find_max/services/find_max_numbers.rb
136
+ - lib/find_max/version.rb
137
+ homepage: ''
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: ''
161
+ test_files: []