primes_table 0.1.2

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
+ SHA256:
3
+ metadata.gz: f352b5f4ffa9e140c109f96cfaaf234342663ea1cc4d2635cc8f56cff3368f5b
4
+ data.tar.gz: 16a386e64065e25e5da7c0b92d5e522f332359ce058093011878e1a6dbc651bb
5
+ SHA512:
6
+ metadata.gz: cc4bef2bf94a94698ba7f5acc4973a1585c3f424dc8e491ceba1d311c8b844cb3957076b79c7c058c824170888b8a448368dc23b8332d0a8e610fac2841e5e75
7
+ data.tar.gz: d523432aa46ed8f95fc818c83e660ecfba7facd66faebfdf5ea3beea001fce8294fa458cf29083b9abf5f95efd89c9abe4ecb2346142f01734ad8289a814196e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ .idea
6
+ .byebug_history
7
+ coverage
8
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at nicolas.s.vidal@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
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 primes_table.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ primes_table (0.1.2)
5
+ methadone (~> 1.9, >= 1.9.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aruba (0.14.5)
11
+ childprocess (>= 0.6.3, < 0.10.0)
12
+ contracts (~> 0.9)
13
+ cucumber (>= 1.3.19)
14
+ ffi (~> 1.9.10)
15
+ rspec-expectations (>= 2.99)
16
+ thor (~> 0.19)
17
+ backports (3.11.2)
18
+ builder (3.2.3)
19
+ byebug (10.0.2)
20
+ childprocess (0.9.0)
21
+ ffi (~> 1.0, >= 1.0.11)
22
+ contracts (0.16.0)
23
+ cucumber (3.1.0)
24
+ builder (>= 2.1.2)
25
+ cucumber-core (~> 3.1.0)
26
+ cucumber-expressions (~> 5.0.4)
27
+ cucumber-wire (~> 0.0.1)
28
+ diff-lcs (~> 1.3)
29
+ gherkin (~> 5.0)
30
+ multi_json (>= 1.7.5, < 2.0)
31
+ multi_test (>= 0.1.2)
32
+ cucumber-core (3.1.0)
33
+ backports (>= 3.8.0)
34
+ cucumber-tag_expressions (~> 1.1.0)
35
+ gherkin (>= 5.0.0)
36
+ cucumber-expressions (5.0.17)
37
+ cucumber-tag_expressions (1.1.1)
38
+ cucumber-wire (0.0.1)
39
+ diff-lcs (1.3)
40
+ docile (1.3.0)
41
+ ffi (1.9.23)
42
+ gherkin (5.0.0)
43
+ json (2.1.0)
44
+ methadone (1.9.5)
45
+ bundler
46
+ multi_json (1.13.1)
47
+ multi_test (0.1.2)
48
+ rake (12.3.1)
49
+ rdoc (6.0.3)
50
+ rspec (3.7.0)
51
+ rspec-core (~> 3.7.0)
52
+ rspec-expectations (~> 3.7.0)
53
+ rspec-mocks (~> 3.7.0)
54
+ rspec-core (3.7.1)
55
+ rspec-support (~> 3.7.0)
56
+ rspec-expectations (3.7.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.7.0)
59
+ rspec-mocks (3.7.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.7.0)
62
+ rspec-support (3.7.1)
63
+ simplecov (0.16.1)
64
+ docile (~> 1.1)
65
+ json (>= 1.8, < 3)
66
+ simplecov-html (~> 0.10.0)
67
+ simplecov-html (0.10.2)
68
+ thor (0.20.0)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ aruba (~> 0.14.3)
75
+ bundler (~> 1.16, >= 1.16.1)
76
+ byebug (~> 10.0)
77
+ primes_table!
78
+ rake (~> 12.3)
79
+ rdoc (~> 6.0, >= 6.0.1)
80
+ rspec (~> 3.7)
81
+ simplecov (~> 0.16.1)
82
+
83
+ BUNDLED WITH
84
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,204 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Name: primes_table
191
+ Copyright 2018 Nicolas Sebastian Vidal
192
+
193
+
194
+ Licensed under the Apache License, Version 2.0 (the "License");
195
+ you may not use this file except in compliance with the License.
196
+ You may obtain a copy of the License at
197
+
198
+ http://www.apache.org/licenses/LICENSE-2.0
199
+
200
+ Unless required by applicable law or agreed to in writing, software
201
+ distributed under the License is distributed on an "AS IS" BASIS,
202
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203
+ See the License for the specific language governing permissions and
204
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ [![Maintainability](https://api.codeclimate.com/v1/badges/76cdbb4e023166cc619d/maintainability)](https://codeclimate.com/github/nisevi/primes_table/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/76cdbb4e023166cc619d/test_coverage)](https://codeclimate.com/github/nisevi/primes_table/test_coverage) [![Build Status](https://semaphoreci.com/api/v1/nisevi/primes_table/branches/master/shields_badge.svg)](https://semaphoreci.com/nisevi/primes_table) [![Gem Version](https://badge.fury.io/rb/primes_table.svg)](https://badge.fury.io/rb/primes_table)
2
+
3
+ # PrimesTable
4
+
5
+ Command line tool for printing out a multiplication table of the first N prime numbers.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'primes_table'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install primes_table
22
+
23
+ ## Usage
24
+
25
+ - By default the table it will be generated as a matrix of 10X10;
26
+
27
+ - Only values greater or equal than 10 will be considered for specifying rows or columns;
28
+
29
+ - If you enter a value minor than 10, it will default to 10;
30
+
31
+ - Only integer values are considered. For example, if you enter an string, it will be converted to integer, the result will be 0 (zero) and will default to 10 because zero is minor than 10;
32
+
33
+ - Options:
34
+ - `-h, --help` to see the available options;
35
+ - `-r, --rows ROWS` to specify how many rows;
36
+ - `-c, --columns COLUMNS` to specify how many columns;
37
+ - `--version` it will give you the version of the gem you are using;
38
+
39
+ - Command examples:
40
+ - `primes_table --version`;
41
+ - `primes_table --help`;
42
+ - `primes_table`;
43
+ - `primes_table -r 17`;
44
+ - `primes_table -c 23`;
45
+ - `primes_table -r 17 -c 23`;
46
+
47
+ ## Tests
48
+
49
+ - Rspec:
50
+ - `bundle exec rspec`
51
+
52
+ ## Development
53
+
54
+ When working on this gem locally, if you want to run it, you just need to:
55
+
56
+ `$ bundle exec bin/primes_table`
57
+
58
+ and you will get the default output:
59
+
60
+ | | 2 | 3 | 5 | 7 |
61
+ |:---:|:----:|:---:|:----:|:----:|
62
+ | 2 | 4 | 6 | 10 | 14 |
63
+ | 3 | 6 | 9 | 15 | 21 |
64
+ | 5 | 10 | 15 | 25 | 35 |
65
+ | 7 | 14 | 21 | 35 | 49 |
66
+
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = primes_table - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) 2018 YOUR NAME
5
+
6
+
7
+ License:: apache, see LICENSE.txt
8
+
9
+
10
+
11
+ DESCRIBE YOUR GEM HERE
12
+
13
+ == Links
14
+
15
+ * {Source on Github}[LINK TO GITHUB]
16
+ * RDoc[LINK TO RDOC.INFO]
17
+
18
+ == Install
19
+
20
+ == Examples
21
+
22
+ == Contributing
23
+
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ def dump_load_path
4
+ puts $LOAD_PATH.join("\n")
5
+ found = nil
6
+ $LOAD_PATH.each do |path|
7
+ if File.exist?(File.join(path, 'rspec'))
8
+ puts "Found rspec in #{path}"
9
+ found = found_core?(path)
10
+ end
11
+ end
12
+ found_is_nil?(found)
13
+ end
14
+
15
+ def found_core?(path)
16
+ if File.exist?(File.join(path, 'rspec', 'core'))
17
+ puts 'Found core'
18
+ found_rake_task?(path)
19
+ else
20
+ puts '!!! no core'
21
+ nil
22
+ end
23
+ end
24
+
25
+ def found_rake_task?(path)
26
+ if File.exist?(File.join(path, 'rspec', 'core', 'rake_task'))
27
+ puts 'Found rake_task'
28
+ path
29
+ else
30
+ puts '!! no rake_task'
31
+ nil
32
+ end
33
+ end
34
+
35
+ def found_is_nil?(found)
36
+ if found.nil?
37
+ puts "Didn't find rspec/core/rake_task anywhere"
38
+ else
39
+ puts "Found in #{path}"
40
+ end
41
+ end
42
+
43
+ require 'bundler'
44
+ require 'rake/clean'
45
+
46
+ begin
47
+ require 'rspec/core/rake_task'
48
+ rescue LoadError
49
+ dump_load_path
50
+ raise
51
+ end
52
+
53
+ require 'cucumber'
54
+ require 'cucumber/rake/task'
55
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
56
+ require 'rdoc/task'
57
+
58
+ include Rake::DSL
59
+
60
+ Bundler::GemHelper.install_tasks
61
+
62
+ RSpec::Core::RakeTask.new do |t|
63
+ # Put spec opts in a file named .rspec in root
64
+ end
65
+
66
+ CUKE_RESULTS = 'results.html'
67
+ CLEAN << CUKE_RESULTS
68
+ Cucumber::Rake::Task.new(:features) do |t|
69
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
70
+ t.fork = false
71
+ end
72
+
73
+ Rake::RDocTask.new do |rd|
74
+ rd.main = 'README.rdoc'
75
+ rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'bin/**/*')
76
+ end
77
+
78
+ task default: %i[spec features]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "primes_table"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/primes_table ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'primes_table.rb'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+
11
+ main do
12
+ rows = options[:rows].to_i < 10 ? 10 : options[:rows].to_i
13
+ columns = options[:columns].to_i < 10 ? 10 : options[:columns].to_i
14
+ args = { rows: rows, columns: columns }
15
+ matrix = Matrix.new(args)
16
+ matrix.print
17
+ end
18
+
19
+ description 'Prints out a multiplication table of the first N prime numbers.'
20
+
21
+ on('-r ROWS', '--rows', 'Amount of rows in table. Must be integer. Default value is 10.')
22
+ on('-c COLUMNS', '--columns', 'Amount of columns in the table. Must be integer. Default value is 10.')
23
+
24
+ version PrimesTable::VERSION
25
+
26
+ go!
27
+ 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,2 @@
1
+ require 'primes_table/version'
2
+ require 'primes_table/matrix'
@@ -0,0 +1,82 @@
1
+ class Matrix
2
+ attr_accessor :rows_header, :columns_header, :table
3
+
4
+ def initialize(args)
5
+ rows = header(args[:rows])
6
+ columns = header(args[:columns])
7
+ @table = load_table(rows, columns)
8
+ @rows_header = rows
9
+ @columns_header = columns
10
+ end
11
+
12
+ def print
13
+ distance = last_value.to_s.length
14
+ puts format_columns_header(distance)
15
+ table.each_with_index do |row, index|
16
+ puts format_rows(row, index, distance)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def load_table(rows, columns)
23
+ collection = []
24
+ rows.each_with_index do |row_value, row_index|
25
+ collection << []
26
+ columns.each do |column|
27
+ collection[row_index] << row_value * column
28
+ end
29
+ end
30
+ collection
31
+ end
32
+
33
+ def last_value
34
+ table[-1][-1]
35
+ end
36
+
37
+ def format_columns_header(distance)
38
+ "#{' ' * distance} #{format_collection(columns_header, distance)}"
39
+ end
40
+
41
+ def format_rows(row, index, distance)
42
+ len_index = rows_header[index].to_s.length
43
+ format_prime = "#{rows_header[index]}#{' ' * (distance - len_index)}"
44
+ collection = format_collection(row, distance)
45
+ "#{format_prime} | #{collection}"
46
+ end
47
+
48
+ def format_collection(list, distance)
49
+ list.collect { |i| ' ' * (distance - i.to_s.size) + i.to_s }.join(' ').to_s
50
+ end
51
+
52
+ def header(max)
53
+ flags = [true] * (max + 1)
54
+ flags[0] = flags[1] = false
55
+ prime = 2
56
+ while prime <= Math.sqrt(max)
57
+ cross_off(flags, prime)
58
+ prime = next_prime(flags, prime)
59
+ end
60
+ process_flags(flags)
61
+ end
62
+
63
+ def cross_off(flags, prime)
64
+ (prime * prime..flags.length).step(prime).each do |i|
65
+ flags[i] = false
66
+ end
67
+ end
68
+
69
+ def next_prime(flags, prime)
70
+ following = prime + 1
71
+ following += 1 while following < flags.length && !flags[following]
72
+ following
73
+ end
74
+
75
+ def process_flags(flags)
76
+ primes = []
77
+ flags.each_with_index do |value, index|
78
+ primes << index if value
79
+ end
80
+ primes
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module PrimesTable
2
+ VERSION = '0.1.2'.freeze
3
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'primes_table/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'primes_table'
7
+ spec.license = 'Apache-2.0'
8
+ spec.version = PrimesTable::VERSION
9
+ spec.authors = ['Nicolas Sebastian Vidal']
10
+ spec.email = ['nicolas.s.vidal@gmail.com']
11
+ spec.summary = 'Prints out a multiplication table of the first N prime numbers.'
12
+ spec.description = 'Command line tool for printing out a multiplication table of the first N prime numbers.'
13
+ spec.homepage = 'https://github.com/nisevi/primes_table'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = 'bin'
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ spec.required_ruby_version = '>= 2.5.0'
22
+
23
+ spec.add_development_dependency 'aruba', '~> 0.14.3'
24
+ spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
25
+ spec.add_development_dependency 'byebug', '~> 10.0'
26
+ spec.add_development_dependency 'rake', '~> 12.3'
27
+ spec.add_development_dependency 'rdoc', '~> 6.0', '>= 6.0.1'
28
+ spec.add_dependency 'methadone', '~> 1.9', '>= 1.9.5'
29
+ spec.add_development_dependency 'rspec', '~> 3.7'
30
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
31
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: primes_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Sebastian Vidal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aruba
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.14.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.16.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.16'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.16.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: byebug
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.3'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.3'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rdoc
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '6.0'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 6.0.1
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '6.0'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 6.0.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: methadone
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.9'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.9.5
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.9'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 1.9.5
115
+ - !ruby/object:Gem::Dependency
116
+ name: rspec
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.7'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: '3.7'
129
+ - !ruby/object:Gem::Dependency
130
+ name: simplecov
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: 0.16.1
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: 0.16.1
143
+ description: Command line tool for printing out a multiplication table of the first
144
+ N prime numbers.
145
+ email:
146
+ - nicolas.s.vidal@gmail.com
147
+ executables:
148
+ - console
149
+ - primes_table
150
+ - setup
151
+ extensions: []
152
+ extra_rdoc_files: []
153
+ files:
154
+ - ".gitignore"
155
+ - ".rspec"
156
+ - CODE_OF_CONDUCT.md
157
+ - Gemfile
158
+ - Gemfile.lock
159
+ - LICENSE.txt
160
+ - README.md
161
+ - README.rdoc
162
+ - Rakefile
163
+ - bin/console
164
+ - bin/primes_table
165
+ - bin/setup
166
+ - lib/primes_table.rb
167
+ - lib/primes_table/matrix.rb
168
+ - lib/primes_table/version.rb
169
+ - primes_table.gemspec
170
+ homepage: https://github.com/nisevi/primes_table
171
+ licenses:
172
+ - Apache-2.0
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 2.5.0
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.7.6
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Prints out a multiplication table of the first N prime numbers.
194
+ test_files: []