danielharan-support 0.1.1 → 0.2.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/lib/support.rb +9 -0
- data/lib/support/hash_ext.rb +17 -0
- data/lib/support/range_ext.rb +11 -0
- data/support.gemspec +4 -4
- data/test/hash_ext_test.rb +1 -2
- data/test/range_ext_test.rb +16 -0
- data/test/test_helper.rb +2 -0
- metadata +10 -4
- data/lib/hash_ext.rb +0 -15
data/lib/support.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Support
|
2
|
+
module HashExt
|
3
|
+
# Recursively adds hashes
|
4
|
+
# > {:a => 1, :b => 1} + {:a => 1}
|
5
|
+
# => {:a => 2, :b => 1}
|
6
|
+
def +(other)
|
7
|
+
(self.keys + other.keys).uniq.each do |key|
|
8
|
+
if [self[key], other[key]].all?
|
9
|
+
self[key] += other[key]
|
10
|
+
else
|
11
|
+
self[key] ||= other[key] # ignore the nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/support.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{support}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.2.0"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Daniel Haran"]
|
7
7
|
s.date = %q{2008-12-16}
|
8
8
|
s.description = %q{A collection of ruby core extensions I find useful.}
|
9
9
|
s.email = %q{chebuctonian@gmail.com}
|
10
|
-
s.extra_rdoc_files = ["lib/hash_ext.rb", "README.rdoc"]
|
11
|
-
s.files = ["lib/hash_ext.rb", "Manifest", "MIT-LICENSE", "README.rdoc", "test/hash_ext_test.rb", "
|
10
|
+
s.extra_rdoc_files = ["lib/support/hash_ext.rb", "lib/support/range_ext.rb", "lib/support.rb", "README.rdoc"]
|
11
|
+
s.files = ["lib/support/hash_ext.rb", "lib/support/range_ext.rb", "lib/support.rb", "Manifest", "MIT-LICENSE", "README.rdoc", "support.gemspec", "test/hash_ext_test.rb", "test/range_ext_test.rb", "test/test_helper.rb"]
|
12
12
|
s.homepage = %q{http://github.com/danielharan/support}
|
13
13
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Support", "--main", "README.rdoc"]
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
s.rubyforge_project = %q{support}
|
16
16
|
s.rubygems_version = %q{1.2.0}
|
17
17
|
s.summary = %q{A collection of ruby core extensions I find useful.}
|
18
|
-
s.test_files = ["test/hash_ext_test.rb", "test/range_ext_test.rb"]
|
18
|
+
s.test_files = ["test/hash_ext_test.rb", "test/range_ext_test.rb", "test/test_helper.rb"]
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/test/hash_ext_test.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RangeTest < Test::Unit::TestCase
|
4
|
+
def test_interpolate_for_integers
|
5
|
+
assert_equal [1,3,5,7,9], (1..10).interpolate(2)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_interpolate_every_hour_on_time
|
9
|
+
start_date = Time.now
|
10
|
+
end_date = start_date + 3600 * 3 # 3 hours later
|
11
|
+
|
12
|
+
interpolated = (start_date .. end_date).interpolate(3600)
|
13
|
+
assert_equal 4, interpolated.length
|
14
|
+
assert_equal 3, (start_date...end_date).interpolate(3600).size
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danielharan-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Haran
|
@@ -20,16 +20,21 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- lib/hash_ext.rb
|
23
|
+
- lib/support/hash_ext.rb
|
24
|
+
- lib/support/range_ext.rb
|
25
|
+
- lib/support.rb
|
24
26
|
- README.rdoc
|
25
27
|
files:
|
26
|
-
- lib/hash_ext.rb
|
28
|
+
- lib/support/hash_ext.rb
|
29
|
+
- lib/support/range_ext.rb
|
30
|
+
- lib/support.rb
|
27
31
|
- Manifest
|
28
32
|
- MIT-LICENSE
|
29
33
|
- README.rdoc
|
30
|
-
- test/hash_ext_test.rb
|
31
34
|
- support.gemspec
|
35
|
+
- test/hash_ext_test.rb
|
32
36
|
- test/range_ext_test.rb
|
37
|
+
- test/test_helper.rb
|
33
38
|
has_rdoc: false
|
34
39
|
homepage: http://github.com/danielharan/support
|
35
40
|
post_install_message:
|
@@ -64,3 +69,4 @@ summary: A collection of ruby core extensions I find useful.
|
|
64
69
|
test_files:
|
65
70
|
- test/hash_ext_test.rb
|
66
71
|
- test/range_ext_test.rb
|
72
|
+
- test/test_helper.rb
|
data/lib/hash_ext.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
# Recursively adds hashes
|
3
|
-
# > {:a => 1, :b => 1} + {:a => 1}
|
4
|
-
# => {:a => 2, :b => 1}
|
5
|
-
def +(other)
|
6
|
-
(self.keys + other.keys).uniq.each do |key|
|
7
|
-
if [self[key], other[key]].all?
|
8
|
-
self[key] += other[key]
|
9
|
-
else
|
10
|
-
self[key] ||= other[key] # ignore the nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|