utilities 0.0.3 → 0.0.4
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 +9 -5
- data/lib/version.rb +1 -1
- metadata +3 -3
data/lib/utilities.rb
CHANGED
|
@@ -46,6 +46,11 @@ class String
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
class Numeric
|
|
49
|
+
# Convert to degrees
|
|
50
|
+
def degrees
|
|
51
|
+
self * Math::PI / 180
|
|
52
|
+
end
|
|
53
|
+
|
|
49
54
|
# Calculate the rank of self based on provided min and max
|
|
50
55
|
def rank min, max
|
|
51
56
|
s, min, max = self.to_f, min.to_f, max.to_f
|
|
@@ -67,9 +72,7 @@ module Utilities
|
|
|
67
72
|
module Statistics
|
|
68
73
|
# Add each object of the array to each other in order to get the sum, as long as all objects respond to + operator
|
|
69
74
|
def sum
|
|
70
|
-
inject(
|
|
71
|
-
sum ? sum + x : x
|
|
72
|
-
end
|
|
75
|
+
inject( :+ )
|
|
73
76
|
end
|
|
74
77
|
|
|
75
78
|
# Calculate the mean of the array, as long as all objects respond to / operator
|
|
@@ -100,7 +103,7 @@ module Utilities
|
|
|
100
103
|
return nil if empty?
|
|
101
104
|
a = sort unless already_sorted
|
|
102
105
|
m_pos = size / 2
|
|
103
|
-
size % 2 == 1 ? a[m_pos] : a[m_pos-1..m_pos].mean
|
|
106
|
+
size % 2 == 1 ? a[m_pos] : a[m_pos-1..m_pos].extend(Utilities::Statistics).mean
|
|
104
107
|
end
|
|
105
108
|
|
|
106
109
|
# Return an array of modes with their corresponding occurences
|
|
@@ -111,7 +114,7 @@ module Utilities
|
|
|
111
114
|
end
|
|
112
115
|
|
|
113
116
|
# Return all statistics from the array in a simple hash
|
|
114
|
-
def
|
|
117
|
+
def statistics
|
|
115
118
|
{
|
|
116
119
|
:size => size,
|
|
117
120
|
:sum => sum,
|
|
@@ -123,5 +126,6 @@ module Utilities
|
|
|
123
126
|
:modes => modes
|
|
124
127
|
}
|
|
125
128
|
end
|
|
129
|
+
alias_method :stats, :statistics
|
|
126
130
|
end
|
|
127
131
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: utilities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Christian Blais
|