to_fib 1.0.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 +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/lib/to_fib/to_fib.rb +29 -0
- data/lib/to_fib/version.rb +14 -0
- data/lib/to_fib.rb +2 -0
- data/test/test_helper.rb +10 -0
- data/test/test_to_fib.rb +25 -0
- data/to_fib.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5db8d9e23971783be7dcb43fc2dbae7cc6aeaba
|
4
|
+
data.tar.gz: e69362a20caef17b0dd39729d98867faf3c297e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f5692e1685f77c8d57cae32b663d49f1881c0e97f6d5ed354344230109faa4b52ebfee984a89de424e98fdcbdc899723dcc4fe1fa898eaa949fc35faea05953
|
7
|
+
data.tar.gz: a2839a3d3c700cd9cd07313567afae4c1b836bf1e89dce247aa3c6a876b592fcffa49fde9f95bcfccde47b5e048a5daf3c6da76bf31087354956f4c8b15d01ae
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
to_fib (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
builder (3.2.2)
|
11
|
+
minitest (5.8.0)
|
12
|
+
minitest-reporters (1.0.20)
|
13
|
+
ansi
|
14
|
+
builder
|
15
|
+
minitest (>= 5.0)
|
16
|
+
ruby-progressbar
|
17
|
+
rake (0.9.6)
|
18
|
+
ruby-progressbar (1.7.5)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler
|
25
|
+
minitest
|
26
|
+
minitest-reporters
|
27
|
+
rake (~> 0)
|
28
|
+
to_fib!
|
29
|
+
|
30
|
+
BUNDLED WITH
|
31
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dave De Carlo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module ToFib
|
2
|
+
module ObjectExtension
|
3
|
+
def to_fib
|
4
|
+
fibonacci(self).reverse_each.take(2).min {|a, b| (self-a).abs <=> (self-b).abs}
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def fibonacci(max=Float::INFINITY)
|
10
|
+
return to_enum(__method__, max) unless block_given?
|
11
|
+
yield previous = 0
|
12
|
+
while (i ||= 1) <= max
|
13
|
+
yield i
|
14
|
+
i, previous = previous + i, i
|
15
|
+
end
|
16
|
+
yield i
|
17
|
+
previous
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Fixnum
|
24
|
+
include ToFib::ObjectExtension
|
25
|
+
end
|
26
|
+
|
27
|
+
class Bignum
|
28
|
+
include ToFib::ObjectExtension
|
29
|
+
end
|
data/lib/to_fib.rb
ADDED
data/test/test_helper.rb
ADDED
data/test/test_to_fib.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestToFib < BaseTest
|
4
|
+
|
5
|
+
def test_version
|
6
|
+
refute_equal nil, ToFib::Version
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_13
|
10
|
+
assert_equal 13, 13.to_fib
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_20
|
14
|
+
assert_equal 21, 21.to_fib
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_40
|
18
|
+
assert_equal 34, 40.to_fib
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_900000000000000000000000000000000000000000000000000000000000000000000
|
22
|
+
assert_equal 1082459262056433063877940200966638133809015267665311237542082678938909, 900000000000000000000000000000000000000000000000000000000000000000000.to_fib
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/to_fib.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'to_fib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "to_fib"
|
8
|
+
spec.version = ToFib::Version
|
9
|
+
spec.authors = ["Dave De Carlo"]
|
10
|
+
spec.email = ["dec114@gmail.com"]
|
11
|
+
spec.summary = %q{to the nearest fibonacci number}
|
12
|
+
spec.homepage = "https://github.com/quotha/to_fib"
|
13
|
+
spec.description = "The to_fib Ruby Gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", '~> 0'
|
22
|
+
spec.add_development_dependency "rake", '~> 0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_fib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave De Carlo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-20 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: The to_fib Ruby Gem
|
42
|
+
email:
|
43
|
+
- dec114@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/to_fib.rb
|
55
|
+
- lib/to_fib/to_fib.rb
|
56
|
+
- lib/to_fib/version.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- test/test_to_fib.rb
|
59
|
+
- to_fib.gemspec
|
60
|
+
homepage: https://github.com/quotha/to_fib
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: to the nearest fibonacci number
|
84
|
+
test_files:
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/test_to_fib.rb
|