more_core_extensions 1.1.0 → 1.1.1

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/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.2"
4
3
  - "1.9.3"
5
4
  - jruby-19mode # JRuby in 1.9 mode
6
5
  - rbx-19mode
data/README.md CHANGED
@@ -11,12 +11,23 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
11
11
  ## Extensions Provided
12
12
 
13
13
  * Array
14
+ * delete_nils
15
+ * delete_blanks
16
+ * delete_blank_paths
14
17
  * duplicates
18
+ * delete_path
15
19
  * include_any?
16
20
  * include_none?
17
21
  * include_all?
22
+ * fetch_path
23
+ * find_path
24
+ * has_key_path?
25
+ * include_path?
26
+ * key_path?
27
+ * member_path?
18
28
  * random_index
19
29
  * random_element
30
+ * store_path
20
31
  * stretch
21
32
  * stretch!
22
33
  * zip_stretched
@@ -24,13 +35,15 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
24
35
  * Hash
25
36
  * delete_nils
26
37
  * delete_blanks
38
+ * delete_blank_paths
39
+ * delete_path
27
40
  * fetch_path
41
+ * find_path
28
42
  * has_key_path?
29
43
  * include_path?
30
44
  * key_path?
31
45
  * member_path?
32
46
  * store_path
33
- * delete_path
34
47
  * String
35
48
  * email?
36
49
  * domain_name?
@@ -3,17 +3,21 @@ module MoreCoreExtensions
3
3
  #
4
4
  # Picks a valid index randomly
5
5
  #
6
- # [1, 2, 3, 4, 2, 4].random_index #=> random number between 0..5
6
+ # [1, 2, 3, 4, 2, 4].random_index # => random number between 0..5
7
7
  def random_index
8
- rand(self.size)
8
+ case self.size
9
+ when 0; nil
10
+ when 1; 0
11
+ else rand(0...self.size)
12
+ end
9
13
  end
10
14
 
11
15
  #
12
16
  # Picks an element randomly
13
17
  #
14
- # [1, 2, 3, 4, 2, 4].random_element #=> any randomly selected element in Array
18
+ # [1, 2, 3, 4, 2, 4].random_element # => random element in Array
15
19
  def random_element
16
- self[self.random_index]
20
+ sample
17
21
  end
18
22
  end
19
23
  end
@@ -28,7 +28,7 @@ module MoreCoreExtensions
28
28
  ipv4? || ipv6?
29
29
  end
30
30
 
31
- RE_INTEGER = %r{^[0-9]+$}
31
+ RE_INTEGER = %r{^-?[0-9]+$}
32
32
  def integer?
33
33
  !!(self =~ RE_INTEGER)
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module MoreCoreExtensions
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe Array do
4
+ around do |example|
5
+ old_seed = srand(12072)
6
+ example.call
7
+ srand(old_seed)
8
+ end
9
+
10
+ it '#random_index' do
11
+ 20.times.collect { [].random_index }.uniq.sort.should == [nil]
12
+ 20.times.collect { %w{a}.random_index }.uniq.sort.should == [0]
13
+ 20.times.collect { %w{a b}.random_index }.uniq.sort.should == [0, 1]
14
+ 20.times.collect { %w{a b c d}.random_index }.uniq.sort.should == [0, 1, 2, 3]
15
+ end
16
+
17
+ it '#random_element' do
18
+ 20.times.collect { [].random_element }.uniq.sort.should == [nil]
19
+ 20.times.collect { %w{a}.random_element }.uniq.sort.should == %w{a}
20
+ 20.times.collect { %w{a b}.random_element }.uniq.sort.should == %w{a b}
21
+ 20.times.collect { %w{a b c d}.random_element }.uniq.sort.should == %w{a b c d}
22
+ end
23
+ end
@@ -4,6 +4,7 @@ describe String do
4
4
  it '#email?' do
5
5
  "john@example.com".should be_email
6
6
  "john.doe@example.com".should be_email
7
+
7
8
  "john.doe@examplecom".should_not be_email
8
9
  "john.doe@example-com".should_not be_email
9
10
  "".should_not be_email
@@ -12,6 +13,7 @@ describe String do
12
13
 
13
14
  it '#domain_name?' do
14
15
  "example.com".should be_domain_name
16
+
15
17
  "example..com".should_not be_domain_name
16
18
  "john.doe@example.com".should_not be_domain_name
17
19
  "".should_not be_domain_name
@@ -54,8 +56,19 @@ describe String do
54
56
  "foo".should_not be_ipaddress
55
57
  end
56
58
 
59
+ it "#integer?" do
60
+ "100".should be_integer
61
+ "-100".should be_integer
62
+
63
+ "".should_not be_integer
64
+ "100.2".should_not be_integer
65
+ "A".should_not be_integer
66
+ "100A".should_not be_integer
67
+ end
68
+
57
69
  it '#guid?' do
58
70
  '01234567-89ab-cdef-abcd-ef0123456789'.should be_guid
71
+
59
72
  '012ZZZ67-89ab-cdef-abcd-ef0123456789'.should_not be_guid
60
73
  "".should_not be_guid
61
74
  "foo".should_not be_guid
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: more_core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-04 00:00:00.000000000 Z
12
+ date: 2013-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -129,6 +129,7 @@ files:
129
129
  - spec/core_ext/array/duplicates_spec.rb
130
130
  - spec/core_ext/array/inclusions_spec.rb
131
131
  - spec/core_ext/array/nested_spec.rb
132
+ - spec/core_ext/array/random_spec.rb
132
133
  - spec/core_ext/array/stretch_spec.rb
133
134
  - spec/core_ext/array/tableize_spec.rb
134
135
  - spec/core_ext/hash/deletes_spec.rb
@@ -149,12 +150,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
150
  - - ! '>='
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
153
+ segments:
154
+ - 0
155
+ hash: -105105913744193919
152
156
  required_rubygems_version: !ruby/object:Gem::Requirement
153
157
  none: false
154
158
  requirements:
155
159
  - - ! '>='
156
160
  - !ruby/object:Gem::Version
157
161
  version: '0'
162
+ segments:
163
+ - 0
164
+ hash: -105105913744193919
158
165
  requirements: []
159
166
  rubyforge_project:
160
167
  rubygems_version: 1.8.25
@@ -167,6 +174,7 @@ test_files:
167
174
  - spec/core_ext/array/duplicates_spec.rb
168
175
  - spec/core_ext/array/inclusions_spec.rb
169
176
  - spec/core_ext/array/nested_spec.rb
177
+ - spec/core_ext/array/random_spec.rb
170
178
  - spec/core_ext/array/stretch_spec.rb
171
179
  - spec/core_ext/array/tableize_spec.rb
172
180
  - spec/core_ext/hash/deletes_spec.rb