utilities 0.0.9 → 0.0.10
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/utilities.rb +21 -3
- data/lib/version.rb +1 -1
- metadata +8 -5
data/lib/utilities.rb
CHANGED
@@ -5,6 +5,16 @@ module Kernel
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
+
class Object
|
9
|
+
def within? enumerable
|
10
|
+
if enumerable.is_a? Range
|
11
|
+
enumerable.cover?(self)
|
12
|
+
else
|
13
|
+
enumerable.min <= self && self <= enumerable.max
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
class Range
|
9
19
|
# Return a range containing elements common to the two ranges, with no duplicates
|
10
20
|
def intersection range
|
@@ -22,6 +32,14 @@ class Range
|
|
22
32
|
def overlap? range
|
23
33
|
!(self & range).nil?
|
24
34
|
end
|
35
|
+
|
36
|
+
# Adds cover? if not defined (like in previous rubies)
|
37
|
+
unless self.instance_methods.include?(:cover?)
|
38
|
+
def cover? object
|
39
|
+
ends = [self.first, self.last]
|
40
|
+
ends.min <= object && object <= ends.max
|
41
|
+
end
|
42
|
+
end
|
25
43
|
end
|
26
44
|
|
27
45
|
class DateTime
|
@@ -178,7 +196,7 @@ module Utilities
|
|
178
196
|
|
179
197
|
# Return the first quartile of self
|
180
198
|
def first_quartile( already_sorted = false )
|
181
|
-
return nil
|
199
|
+
return nil if size < 4
|
182
200
|
a = already_sorted ? self : sort
|
183
201
|
a[0..((size / 2) - 1)].extend(Utilities::Statistics).median( true )
|
184
202
|
end
|
@@ -186,7 +204,7 @@ module Utilities
|
|
186
204
|
|
187
205
|
# Return the last quartile of self
|
188
206
|
def last_quartile( already_sorted = false )
|
189
|
-
return nil
|
207
|
+
return nil if size < 4
|
190
208
|
a = already_sorted ? self : sort
|
191
209
|
a[((size / 2) + 1)..-1].extend(Utilities::Statistics).median( true )
|
192
210
|
end
|
@@ -200,7 +218,7 @@ module Utilities
|
|
200
218
|
|
201
219
|
# Calculate the interquartile range of self
|
202
220
|
def interquartile_range( already_sorted = false )
|
203
|
-
return nil
|
221
|
+
return nil if size < 4
|
204
222
|
a = sort_and_extend( already_sorted )
|
205
223
|
a.last_quartile - a.first_quartile
|
206
224
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Christian Blais
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2011-
|
20
|
+
date: 2011-07-13 00:00:00 -04:00
|
20
21
|
default_executable:
|
21
22
|
dependencies: []
|
22
23
|
|
@@ -52,6 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
53
|
requirements:
|
53
54
|
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
55
57
|
segments:
|
56
58
|
- 0
|
57
59
|
version: "0"
|
@@ -60,13 +62,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
62
|
requirements:
|
61
63
|
- - ">="
|
62
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
63
66
|
segments:
|
64
67
|
- 0
|
65
68
|
version: "0"
|
66
69
|
requirements: []
|
67
70
|
|
68
71
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.6.2
|
70
73
|
signing_key:
|
71
74
|
specification_version: 3
|
72
75
|
summary: Few utilities include in all my projects
|