multipri 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +10 -31
- data/bin/multipri +7 -0
- data/docs/table-10x10.png +0 -0
- data/lib/multipri/app.rb +24 -0
- data/lib/multipri/cli_ui.rb +28 -0
- data/lib/multipri/primes_table.rb +60 -0
- data/lib/multipri/version.rb +1 -1
- data/lib/multipri.rb +1 -1
- data/multipri.gemspec +1 -0
- metadata +22 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cc539343273ac7d679fb1a6cca3d05a1a3b5aba
|
4
|
+
data.tar.gz: fa008e41f81b0c5c99793d2ee7205510edee99ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b36726683fec12d6e789d6b2bc92877df4b2de409cdeab6f2800667b3592f77670200a67cdacd470316e71f95928b302743164e44768c8a05377a1649f0051
|
7
|
+
data.tar.gz: ce786eed2d8bcb27f3d377697cb0d2478962d1ffc9395b169d2024a792bf1b432b8a7638e626028ca501c30dcd041dfbc55fa5ee5c97601344e7e3827b98e927
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
multipri
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4
|
data/README.md
CHANGED
@@ -1,41 +1,20 @@
|
|
1
|
-
# Multipri
|
1
|
+
# Multipri: Prime Multiplication Table
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/madis/multipri.svg?branch=master)](https://travis-ci.org/madis/multipri)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'multipri'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install multipri
|
5
|
+
Program that prints a multiplication table of primes numbers.
|
6
|
+
The program should takes an argument from the command line that specifies the amount of prime numbers to generate and print out a multiplication table for these prime numbers.
|
22
7
|
|
23
8
|
## Usage
|
24
9
|
|
25
|
-
|
10
|
+
1. Install the library with `gem install multipri`
|
11
|
+
2. Run it, passing in the table size: `multipri --count 5`
|
26
12
|
|
27
|
-
|
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).
|
13
|
+
It will output a table similar to the following:
|
32
14
|
|
33
|
-
|
15
|
+
![10x10 table](docs/table-10x10.png)
|
34
16
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
17
|
+
## Development
|
39
18
|
|
40
|
-
|
19
|
+
Run tests with `rspec`
|
41
20
|
|
data/bin/multipri
ADDED
Binary file
|
data/lib/multipri/app.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'cli_ui'
|
2
|
+
require_relative 'primes_table'
|
3
|
+
|
4
|
+
module Multipri
|
5
|
+
class App
|
6
|
+
def self.run(args)
|
7
|
+
new(CliUI, PrimesTable).run(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(ui, table)
|
11
|
+
@ui = ui
|
12
|
+
@table = table
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(input)
|
16
|
+
count = ui.read(input)
|
17
|
+
ui.write(table.generate(count))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :ui, :table
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'terminal-table'
|
3
|
+
|
4
|
+
module Multipri
|
5
|
+
class CliUI
|
6
|
+
def self.read(args)
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.on('-c', '--count [COUNT]', Integer, 'Number of primes to use') do |c|
|
10
|
+
options[:count] = c
|
11
|
+
end
|
12
|
+
end.parse(args)
|
13
|
+
options.fetch(:count)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.write(table)
|
17
|
+
style = {
|
18
|
+
all_separators: false
|
19
|
+
}
|
20
|
+
Terminal::Table.new(style: style) do |t|
|
21
|
+
t.headings = ['', *table.row_titles]
|
22
|
+
table.rows.each do |r|
|
23
|
+
t << [r.title, *r.entries]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'prime'
|
2
|
+
|
3
|
+
module Multipri
|
4
|
+
class PrimesTable
|
5
|
+
class Row
|
6
|
+
attr_reader :title, :entries
|
7
|
+
|
8
|
+
def initialize(title, entries)
|
9
|
+
@title = title
|
10
|
+
@entries = entries
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
other.class == self.class && other.state == self.state
|
15
|
+
@title == other.title
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def state
|
21
|
+
[@title, @entries]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.generate(size)
|
26
|
+
new(size).generate
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(size)
|
30
|
+
@size = size
|
31
|
+
@generated = false
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate
|
35
|
+
primes = Prime.first(@size)
|
36
|
+
@row_titles = primes
|
37
|
+
@rows = primes.map do |p|
|
38
|
+
Row.new(p, primes.map { |q| p * q })
|
39
|
+
end
|
40
|
+
@generated = true
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def rows
|
45
|
+
generate unless generated?
|
46
|
+
@rows
|
47
|
+
end
|
48
|
+
|
49
|
+
def row_titles
|
50
|
+
generate unless generated?
|
51
|
+
@row_titles
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def generated?
|
57
|
+
@generated
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/multipri/version.rb
CHANGED
data/lib/multipri.rb
CHANGED
data/multipri.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
+
spec.add_dependency 'terminal-table', '~>1.7.3'
|
32
33
|
spec.add_development_dependency "bundler", "~> 1.13"
|
33
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
34
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Madis Nõmme
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: terminal-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.3
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,14 +75,21 @@ extra_rdoc_files: []
|
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
64
80
|
- ".travis.yml"
|
65
81
|
- Gemfile
|
66
82
|
- LICENSE.txt
|
67
83
|
- README.md
|
68
84
|
- Rakefile
|
69
85
|
- bin/console
|
86
|
+
- bin/multipri
|
70
87
|
- bin/setup
|
88
|
+
- docs/table-10x10.png
|
71
89
|
- lib/multipri.rb
|
90
|
+
- lib/multipri/app.rb
|
91
|
+
- lib/multipri/cli_ui.rb
|
92
|
+
- lib/multipri/primes_table.rb
|
72
93
|
- lib/multipri/version.rb
|
73
94
|
- multipri.gemspec
|
74
95
|
homepage: https://github.com/madis/multipri
|