danielharan-support 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/support.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'support/hash_ext'
4
+ require 'support/range_ext'
5
+
6
+ module Support
7
+ Hash.send(:include, HashExt)
8
+ Range.send(:include, RangeExt)
9
+ end
@@ -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
@@ -0,0 +1,11 @@
1
+ module Support
2
+ module RangeExt
3
+ def interpolate(increment)
4
+ ret = []
5
+ step(increment) do |incremented|
6
+ ret << incremented
7
+ end
8
+ ret
9
+ end
10
+ end
11
+ 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.1.1"
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", "support.gemspec", "test/range_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
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require "#{File.dirname(__FILE__)}/../lib/hash_ext"
1
+ require 'test_helper'
3
2
 
4
3
  class TestReminder < Test::Unit::TestCase
5
4
  def test_simple_addition
@@ -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
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require "#{File.dirname(__FILE__)}/../lib/support"
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.1.1
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