freighthopper 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
- require 'freighthopper/array/exclude.rb'
2
- require 'freighthopper/array/singular.rb'
3
- require 'freighthopper/array/symbols.rb'
1
+ require 'freighthopper/array/exclude'
2
+ require 'freighthopper/array/singular'
3
+ require 'freighthopper/array/symbols'
4
+ require 'freighthopper/array/inverse_grep'
@@ -0,0 +1,10 @@
1
+ module Enumerable
2
+ def inverse_grep(pattern, &blk)
3
+ inject([]) do |accumulator, value|
4
+ unless pattern === value
5
+ accumulator << (blk ? blk.call(value) : value)
6
+ end
7
+ accumulator
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,19 @@ require File.instance_eval { expand_path join(dirname(__FILE__), 'test_helper')
2
2
  require 'freighthopper'
3
3
 
4
4
  class ArrayTest < Test::Unit::TestCase
5
+ context 'inverse_grep' do
6
+ should 'exclude anything that === matches the pattern' do
7
+ assert_equal (6..10).to_a, (1..10).inverse_grep(1..5)
8
+ end
9
+
10
+ should 'map with the block if provided' do
11
+ start = %w( monday tuesday wednesday thursday friday saturday sunday )
12
+ expected = %w( Monday Tuesday Wednesday Thursday Friday )
13
+
14
+ assert_equal expected, start.inverse_grep(/^s/){|day| day.titlecase}
15
+ end
16
+ end
17
+
5
18
  context 'symbols' do
6
19
  should 'map to sym' do
7
20
  assert_equal [:a, :b, :c, :d, :e], %w( a b c d e ).symbols
@@ -61,4 +74,4 @@ class ArrayTest < Test::Unit::TestCase
61
74
  assert_message 'not singular', e
62
75
  end
63
76
  end
64
- end
77
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freighthopper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 13
10
- version: 0.1.13
9
+ - 14
10
+ version: 0.1.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jacob Rothstein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -07:00
18
+ date: 2010-10-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -37,6 +37,7 @@ files:
37
37
  - lib/freighthopper/antonym_accessor.rb
38
38
  - lib/freighthopper/array.rb
39
39
  - lib/freighthopper/array/exclude.rb
40
+ - lib/freighthopper/array/inverse_grep.rb
40
41
  - lib/freighthopper/array/singular.rb
41
42
  - lib/freighthopper/array/symbols.rb
42
43
  - lib/freighthopper/define_and_alias.rb