matthewrudy-primetable 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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/exe/primetable +24 -0
- data/lib/primetable/formatter.rb +18 -0
- data/lib/primetable/generator.rb +16 -0
- data/lib/primetable/version.rb +3 -0
- data/lib/primetable.rb +20 -0
- data/primetable.gemspec +26 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64f892d28e0dc0337bc88e10fed11f3a80e06cb577e73c1f67daea190241dae4
|
4
|
+
data.tar.gz: fc921a8f6843fad19e48f8088f85887c3abe90db2ef0525a152c096c8b74ae6e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1115a34f67db456f69cd7316ffecbd648aa205cfd173ff4862e36b50894badf5af15fb7265410ea7c3d5dfdc102729c7a12b2f4a19cf6a3826b1cf734cfb109e
|
7
|
+
data.tar.gz: bdd419507f64f4596a471a9e32d8839f42ed9a34a267316aa3c4381d4e38e04210c63ed789843b70d6861cb950e6645f320b33c2be77b9c5e4ead3273f3b0392
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
primetable (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
primetable!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Primetable
|
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/primetable`. 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 'primetable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install primetable
|
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. Then, run `rake spec` to run the tests. 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]/primetable.
|
data/Rakefile
ADDED
data/exe/primetable
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "primetable"
|
5
|
+
|
6
|
+
options = {
|
7
|
+
n: 10
|
8
|
+
}
|
9
|
+
|
10
|
+
# Allow --help to give usage
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: primetable [N]"
|
13
|
+
|
14
|
+
opts.on(
|
15
|
+
"-n N",
|
16
|
+
"--number N",
|
17
|
+
OptionParser::DecimalInteger,
|
18
|
+
"First N primes (default 10)"
|
19
|
+
) do |n|
|
20
|
+
options[:n] = n
|
21
|
+
end
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
puts Primetable.print(options[:n])
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Primetable
|
2
|
+
class Formatter
|
3
|
+
def format(values)
|
4
|
+
# all cells will have the width of the maximum value
|
5
|
+
width = values.map { |row| row.map { |v| v.to_s.length }.max }.max
|
6
|
+
|
7
|
+
str = ""
|
8
|
+
values.each do |row|
|
9
|
+
row.each do |v|
|
10
|
+
str << v.to_s.rjust(width) << " | "
|
11
|
+
end
|
12
|
+
# hack to remove the final space, and add the newline
|
13
|
+
str[-1] = "\n"
|
14
|
+
end
|
15
|
+
str
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/primetable.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "primetable/formatter"
|
2
|
+
require "primetable/generator"
|
3
|
+
require "primetable/version"
|
4
|
+
|
5
|
+
module Primetable
|
6
|
+
def self.print(n)
|
7
|
+
primes = Primetable::Generator.new.generate(n)
|
8
|
+
table = Array.new(n+1) { |i| Array.new(n+1) }
|
9
|
+
primes.each_with_index do |p, i|
|
10
|
+
table[0][i+1] = p
|
11
|
+
table[i+1][0] = p
|
12
|
+
|
13
|
+
primes.each_with_index do |q, j|
|
14
|
+
table[i+1][j+1] = p*q
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Primetable::Formatter.new.format(table)
|
19
|
+
end
|
20
|
+
end
|
data/primetable.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "primetable/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "matthewrudy-primetable"
|
8
|
+
spec.version = Primetable::VERSION
|
9
|
+
spec.authors = ["Matthew Rudy Jacobs"]
|
10
|
+
spec.email = ["matthewrudyjacobs@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Prints out a multiplication table of the first N prime numbers.}
|
13
|
+
spec.description = %q{A command line tool which takes an input N, and prints the first N prime numbers in a multiplication table.}
|
14
|
+
spec.homepage = "https://github.com/matthewrudy/primetable"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matthewrudy-primetable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Rudy Jacobs
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-09 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A command line tool which takes an input N, and prints the first N prime
|
56
|
+
numbers in a multiplication table.
|
57
|
+
email:
|
58
|
+
- matthewrudyjacobs@gmail.com
|
59
|
+
executables:
|
60
|
+
- primetable
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- exe/primetable
|
72
|
+
- lib/primetable.rb
|
73
|
+
- lib/primetable/formatter.rb
|
74
|
+
- lib/primetable/generator.rb
|
75
|
+
- lib/primetable/version.rb
|
76
|
+
- primetable.gemspec
|
77
|
+
homepage: https://github.com/matthewrudy/primetable
|
78
|
+
licenses: []
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.7.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Prints out a multiplication table of the first N prime numbers.
|
100
|
+
test_files: []
|