proxinacci 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "shoulda", ">= 0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.4"
7
+ gem "rcov", ">= 0"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+ rcov (1.0.0)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.4)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Matthew Werner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = proxinacci
2
+
3
+ Proxinacci is a simple gem that adds the closest_fibonacci method to the Fixnum class.
4
+ closest_fibonacci will return the largest integer value from the fibonacci sequence smaller than the integer
5
+ on which it is called.
6
+
7
+ = Usage
8
+
9
+ 30.closest_fibonacci # => 21
10
+ 304.closest_fibonacci # => 233
11
+ 233.closest_fibonacci # => 144
12
+ 1.closest_fibonacci # => 0
13
+ 0.closest_fibonacci # => nil
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Matthew Werner. See LICENSE.txt for
18
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "proxinacci"
18
+ gem.homepage = "http://github.com/mwerner/proxinacci"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Find nearby fibonacci numbers}
21
+ gem.description = %Q{Proxinacci adds a method to any number returning the nearest fibonacci number}
22
+ gem.email = "matthew@culini.com"
23
+ gem.authors = ["Matthew Werner"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "proxinacci #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/proxinacci.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Proxinacci
2
+ def closest_fibonacci
3
+ # Don't allow any zero or negative values
4
+ return nil if self <= 0
5
+
6
+ x, y = 0, 1
7
+ while y < self
8
+ # Progress through the Fibonacci sequence while y is less
9
+ # than the number calling the method
10
+ x, y = y, x + y
11
+ end
12
+
13
+ # At this point x is the largest Fibonacci number smaller than the
14
+ # number calling the method
15
+ return x
16
+ end
17
+ end
18
+ Fixnum.send(:include, Proxinacci)
data/test/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'test/unit'
4
+ require 'shoulda'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'proxinacci'
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ class TestProxinacciTest < Test::Unit::TestCase
4
+ def test_start_of_series
5
+ assert_equal(1.closest_fibonacci, 0)
6
+ assert_equal(2.closest_fibonacci, 1)
7
+ assert_equal(5.closest_fibonacci, 3)
8
+ assert_equal(8.closest_fibonacci, 5)
9
+ assert_equal(13.closest_fibonacci, 8)
10
+ end
11
+
12
+ def test_several_values
13
+ # Produced 10 random numbers in irb and double checked them.
14
+ assert_equal(30.closest_fibonacci, 21)
15
+ assert_equal(304.closest_fibonacci, 233)
16
+ assert_equal(44.closest_fibonacci, 34)
17
+ assert_equal(206.closest_fibonacci, 144)
18
+ assert_equal(436.closest_fibonacci, 377)
19
+ assert_equal(7.closest_fibonacci, 5)
20
+ assert_equal(115.closest_fibonacci, 89)
21
+ assert_equal(232.closest_fibonacci, 144)
22
+ assert_equal(57.closest_fibonacci, 55)
23
+ assert_equal(79.closest_fibonacci, 55)
24
+ end
25
+
26
+ def test_zero
27
+ 0.closest_fibonacci.nil?
28
+ end
29
+
30
+ def test_negative_value
31
+ -1.closest_fibonacci.nil?
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxinacci
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ segments_generated: true
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Matthew Werner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-22 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :development
24
+ name: shoulda
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ segments_generated: true
32
+ version: "0"
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ type: :development
37
+ name: bundler
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ segments_generated: true
47
+ version: 1.0.0
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ type: :development
52
+ name: jeweler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 4
61
+ segments_generated: true
62
+ version: 1.6.4
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ prerelease: false
66
+ type: :development
67
+ name: rcov
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ segments_generated: true
75
+ version: "0"
76
+ requirement: *id004
77
+ description: Proxinacci adds a method to any number returning the nearest fibonacci number
78
+ email: matthew@culini.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files:
84
+ - LICENSE.txt
85
+ - README.rdoc
86
+ files:
87
+ - .document
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - README.rdoc
92
+ - Rakefile
93
+ - VERSION
94
+ - lib/proxinacci.rb
95
+ - test/helper.rb
96
+ - test/test_proxinacci.rb
97
+ has_rdoc: true
98
+ homepage: http://github.com/mwerner/proxinacci
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ segments_generated: true
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ segments_generated: true
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project:
125
+ rubygems_version: 1.3.6
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Find nearby fibonacci numbers
129
+ test_files: []
130
+