range_math 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +48 -0
- data/Rakefile +16 -45
- data/lib/range_math.rb +33 -29
- data/range_math.gemspec +2 -47
- metadata +6 -68
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -24
- data/VERSION +0 -1
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
data/Rakefile
CHANGED
@@ -1,53 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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 = "range_math"
|
18
|
-
gem.homepage = "http://github.com/muflax/range_math"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{do math on ranges}
|
21
|
-
gem.description = %Q{use ranges in math expression}
|
22
|
-
gem.email = "mail@muflax.com"
|
23
|
-
gem.authors = ["muflax"]
|
24
|
-
# dependencies defined in Gemfile
|
1
|
+
desc "open an irb session preloaded with this library"
|
2
|
+
task :console do
|
3
|
+
sh "irb -Ilib -rrange_math"
|
25
4
|
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
5
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
6
|
+
desc "build a gem from the gemspec"
|
7
|
+
task :build do
|
8
|
+
sh "mkdir -p pkg"
|
9
|
+
sh "gem build range_math.gemspec"
|
10
|
+
sh "mv range_math-*.gem pkg/"
|
33
11
|
end
|
34
12
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
39
|
-
test.verbose = true
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
13
|
+
desc "clean pkg"
|
14
|
+
task :clean do
|
15
|
+
sh "rm -f pkg/*"
|
41
16
|
end
|
42
17
|
|
43
|
-
task :default => :test
|
44
18
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "range_math #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
desc "install a gem"
|
20
|
+
task :install => [:clean, :build] do
|
21
|
+
sh "gem install --no-format-executable pkg/range_math-*.gem"
|
53
22
|
end
|
23
|
+
|
24
|
+
task :default => :install
|
data/lib/range_math.rb
CHANGED
@@ -5,43 +5,23 @@
|
|
5
5
|
|
6
6
|
class Range
|
7
7
|
def +(other)
|
8
|
-
|
9
|
-
(self.begin + other.begin)..(self.end + other.end)
|
10
|
-
elsif other.is_a? Numeric
|
11
|
-
(self.begin + other)..(self.end + other)
|
12
|
-
else
|
13
|
-
raise NoMethodError
|
14
|
-
end
|
8
|
+
pair_or_num :+, other
|
15
9
|
end
|
16
10
|
|
17
11
|
def -(other)
|
18
|
-
|
19
|
-
(self.begin - other.begin)..(self.end - other.end)
|
20
|
-
elsif other.is_a? Numeric
|
21
|
-
(self.begin - other)..(self.end - other)
|
22
|
-
else
|
23
|
-
raise NoMethodError
|
24
|
-
end
|
12
|
+
pair_or_num :-, other
|
25
13
|
end
|
26
14
|
|
27
15
|
def *(other)
|
28
|
-
|
29
|
-
(self.begin * other.begin)..(self.end * other.end)
|
30
|
-
elsif other.is_a? Numeric
|
31
|
-
(self.begin * other)..(self.end * other)
|
32
|
-
else
|
33
|
-
raise NoMethodError
|
34
|
-
end
|
16
|
+
pair_or_num :*, other
|
35
17
|
end
|
36
18
|
|
37
19
|
def /(other)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
raise NoMethodError
|
44
|
-
end
|
20
|
+
pair_or_num :/, other.to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_f
|
24
|
+
(self.begin.to_f..self.end.to_f)
|
45
25
|
end
|
46
26
|
|
47
27
|
def average
|
@@ -50,5 +30,29 @@ class Range
|
|
50
30
|
|
51
31
|
def coerce(other)
|
52
32
|
return self, other
|
53
|
-
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def pair_or_num operator, other
|
36
|
+
if other.is_a? Range
|
37
|
+
calc_pairs operator, other
|
38
|
+
elsif other.is_a? Numeric
|
39
|
+
calc_pairs operator, (other..other)
|
40
|
+
else
|
41
|
+
raise NoMethodError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def calc_pairs operator, other
|
46
|
+
parts_x = [self.begin, self.end]
|
47
|
+
parts_y = [other.begin, other.end]
|
48
|
+
|
49
|
+
results = []
|
50
|
+
parts_x.each do |x|
|
51
|
+
parts_y.each do |y|
|
52
|
+
results << x.send(operator, y)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
(results.min..results.max)
|
57
|
+
end
|
54
58
|
end
|
data/range_math.gemspec
CHANGED
@@ -1,62 +1,17 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
1
|
Gem::Specification.new do |s|
|
7
2
|
s.name = "range_math"
|
8
|
-
s.version = "0.
|
3
|
+
s.version = "0.3.0"
|
9
4
|
|
10
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
6
|
s.authors = ["muflax"]
|
12
|
-
s.date = "2011-12-04"
|
13
7
|
s.description = "use ranges in math expression"
|
14
8
|
s.email = "mail@muflax.com"
|
15
9
|
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
10
|
"README"
|
18
11
|
]
|
19
|
-
s.files =
|
20
|
-
".document",
|
21
|
-
"Gemfile",
|
22
|
-
"Gemfile.lock",
|
23
|
-
"LICENSE.txt",
|
24
|
-
"README",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"lib/range_math.rb",
|
28
|
-
"range_math.gemspec",
|
29
|
-
"test/helper.rb",
|
30
|
-
"test/test_range_math.rb"
|
31
|
-
]
|
12
|
+
s.files = `git ls-files`.split("\n")
|
32
13
|
s.homepage = "http://github.com/muflax/range_math"
|
33
|
-
s.licenses = ["MIT"]
|
34
14
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = "1.8.11"
|
36
15
|
s.summary = "do math on ranges"
|
37
|
-
|
38
|
-
if s.respond_to? :specification_version then
|
39
|
-
s.specification_version = 3
|
40
|
-
|
41
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
43
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
44
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
45
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
46
|
-
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
47
|
-
else
|
48
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
49
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
52
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
-
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
60
|
-
end
|
61
16
|
end
|
62
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,85 +9,26 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: shoulda
|
16
|
-
requirement: &9490460 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: *9490460
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: bundler
|
27
|
-
requirement: &9488420 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 1.0.0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *9488420
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: jeweler
|
38
|
-
requirement: &9485580 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 1.6.4
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *9485580
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rcov
|
49
|
-
requirement: &9483160 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *9483160
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: rdoc
|
60
|
-
requirement: &9479460 !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
|
-
requirements:
|
63
|
-
- - ! '>='
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '0'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *9479460
|
12
|
+
date: 2012-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
69
14
|
description: use ranges in math expression
|
70
15
|
email: mail@muflax.com
|
71
16
|
executables: []
|
72
17
|
extensions: []
|
73
18
|
extra_rdoc_files:
|
74
|
-
- LICENSE.txt
|
75
19
|
- README
|
76
20
|
files:
|
77
21
|
- .document
|
78
|
-
-
|
79
|
-
- Gemfile.lock
|
22
|
+
- .gitignore
|
80
23
|
- LICENSE.txt
|
81
24
|
- README
|
82
25
|
- Rakefile
|
83
|
-
- VERSION
|
84
26
|
- lib/range_math.rb
|
85
27
|
- range_math.gemspec
|
86
28
|
- test/helper.rb
|
87
29
|
- test/test_range_math.rb
|
88
30
|
homepage: http://github.com/muflax/range_math
|
89
|
-
licenses:
|
90
|
-
- MIT
|
31
|
+
licenses: []
|
91
32
|
post_install_message:
|
92
33
|
rdoc_options: []
|
93
34
|
require_paths:
|
@@ -98,9 +39,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
39
|
- - ! '>='
|
99
40
|
- !ruby/object:Gem::Version
|
100
41
|
version: '0'
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
hash: -3191188953004532935
|
104
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
43
|
none: false
|
106
44
|
requirements:
|
@@ -109,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
47
|
version: '0'
|
110
48
|
requirements: []
|
111
49
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.8.
|
50
|
+
rubygems_version: 1.8.15
|
113
51
|
signing_key:
|
114
52
|
specification_version: 3
|
115
53
|
summary: do math on ranges
|
data/Gemfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "shoulda", ">= 0"
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.6.4"
|
12
|
-
gem "rcov", ">= 0"
|
13
|
-
gem "rdoc", ">= 0"
|
14
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
-
json (1.6.3)
|
10
|
-
rake (0.9.2.2)
|
11
|
-
rcov (0.9.11)
|
12
|
-
rdoc (3.11)
|
13
|
-
json (~> 1.4)
|
14
|
-
shoulda (2.11.3)
|
15
|
-
|
16
|
-
PLATFORMS
|
17
|
-
ruby
|
18
|
-
|
19
|
-
DEPENDENCIES
|
20
|
-
bundler (~> 1.0.0)
|
21
|
-
jeweler (~> 1.6.4)
|
22
|
-
rcov
|
23
|
-
rdoc
|
24
|
-
shoulda
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|