r_factor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44405404fefee3a11eb8d25e0477426742a240d1
4
- data.tar.gz: b0e88f8e4a7b0b56a0f6b2b021faf08b65f6ed4f
3
+ metadata.gz: 1a5fda8866c54f0e70e9a9c91c76f73af424aa94
4
+ data.tar.gz: bc3d5f8d378deb3b01b3f17c77bb0d310767595c
5
5
  SHA512:
6
- metadata.gz: c249a065796813c88842c2b9f0230e6714c2e15e5db71b2f49b149f3980d31b02b529e18cc1fff0b48386099a59db98017245d69652725b3f581b92af5e760b7
7
- data.tar.gz: 729d6f4bbb542bf5b2c44ac99c0e9cf8cfcc224df1f49dfd3f5c1e4665b21214e29a8fb468bfa975dc385cc02a577192ab2edb4467f7e828882fb553a132495d
6
+ metadata.gz: dd4dd2ffea702e35a1a109270294c640417baf771819ffbd57830a8fcd36dc6bc167faa8438a2e06537f79b35006d347b8cd0774d20cc6cd3455da1d3828a51c
7
+ data.tar.gz: d8e6b7e91ae5157fe2b92038115d85019a9d272ecf0f9f4b1daaee829a3e189c44429359a29155e7e4f9caa243cc4ad915761c018e3376007d49103d69541040
@@ -0,0 +1 @@
1
+ 2.3.1
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Gem Version](https://badge.fury.io/rb/r_factor.svg)](https://badge.fury.io/rb/r_factor)
2
+ [![Build Status](https://travis-ci.org/michaelkitson/r_factor.svg?branch=master)](https://travis-ci.org/michaelkitson/r_factor)
3
+ [![codecov](https://codecov.io/gh/michaelkitson/r_factor/branch/master/graph/badge.svg)](https://codecov.io/gh/michaelkitson/r_factor)
4
+
1
5
  # RFactor
2
6
 
3
7
  A small CLI utility to factor integers.
@@ -15,6 +19,8 @@ Install it yourself with:
15
19
  12741: 3 31 137
16
20
  86157: 3 3 3 3191
17
21
  31628: 2 2 7907
22
+ $ echo "123123123" | factor
23
+ 123123123: 3 3 41 333667
18
24
 
19
25
  ## Development
20
26
 
@@ -1,24 +1,3 @@
1
1
  require_relative 'r_factor/version'
2
+ require_relative 'r_factor/factor'
2
3
  require_relative 'r_factor/cli'
3
-
4
- module RFactor
5
- def self.factor(n)
6
- factors = []
7
- while n >= 2
8
- new_factor = get_smallest_factor(n)
9
- n /= new_factor
10
- factors << new_factor
11
- end
12
- factors
13
- end
14
-
15
- private
16
-
17
- def self.get_smallest_factor(n)
18
- return 2 if n.even?
19
- 3.step(Math.sqrt(n).floor, 2) do |candidate|
20
- return candidate if n % candidate == 0
21
- end
22
- n
23
- end
24
- end
@@ -1,15 +1,26 @@
1
1
  module RFactor
2
2
  class CLI
3
3
  def self.start
4
- ARGV.each do |arg|
5
- number = arg.to_i
6
- unless number.to_s == arg
7
- puts "factor: '#{arg.gsub('\\'){'\\\\'}.gsub("'"){"\\'"}}' is not a valid positive integer"
8
- next
4
+ inputs = ARGV
5
+
6
+ if inputs.empty?
7
+ $stdin.each_line do |line|
8
+ inputs.concat(line.split)
9
9
  end
10
+ end
11
+
12
+ inputs.keep_if do |arg|
13
+ if arg.to_i.to_s == arg
14
+ true
15
+ else
16
+ $stderr.puts "factor: '#{arg.gsub('\\') { '\\\\' }.gsub("'") { "\\'" }}' is not a valid positive integer"
17
+ false
18
+ end
19
+ end
10
20
 
11
- factors = RFactor.factor(number)
12
- puts "#{number}: #{factors.join(' ')}"
21
+ inputs.each do |arg|
22
+ factors = Factor.get_factors(arg.to_i)
23
+ puts "#{arg}: #{factors.join(' ')}"
13
24
  end
14
25
  end
15
26
  end
@@ -0,0 +1,23 @@
1
+ module RFactor
2
+ module Factor
3
+ def self.get_factors(n)
4
+ factors = []
5
+ while n >= 2
6
+ new_factor = get_smallest_factor(n)
7
+ n /= new_factor
8
+ factors << new_factor
9
+ end
10
+ factors
11
+ end
12
+
13
+ private
14
+
15
+ def self.get_smallest_factor(n)
16
+ return 2 if n.even?
17
+ 3.step(Math.sqrt(n).floor, 2) do |candidate|
18
+ return candidate if n % candidate == 0
19
+ end
20
+ n
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module RFactor
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.12'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'minitest', '~> 5.0'
24
+ spec.add_development_dependency 'simplecov', '~> 0.12'
25
+ spec.add_development_dependency 'codecov', '~> 0.1'
24
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kitson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
55
83
  description:
56
84
  email:
57
85
  - michaelskitson@gmail.com
@@ -61,6 +89,7 @@ extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
92
+ - ".ruby-version"
64
93
  - ".travis.yml"
65
94
  - Gemfile
66
95
  - LICENSE.txt
@@ -71,6 +100,7 @@ files:
71
100
  - bin/setup
72
101
  - lib/r_factor.rb
73
102
  - lib/r_factor/cli.rb
103
+ - lib/r_factor/factor.rb
74
104
  - lib/r_factor/version.rb
75
105
  - r_factor.gemspec
76
106
  homepage: https://github.com/michaelkitson/r_factor