rya 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rya/core_extensions.rb +39 -1
- data/lib/rya/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0598dd96f2bf67601ec24f16e84d13f7e5f8c1c
|
4
|
+
data.tar.gz: 57cf0d5cdf6033ceae57e9639784a166d0d9257f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9fd3046fdbc13045f55959d002634eabbe21c551237709a0af24e9668a82d776e55a42356b9606845ddf30f59ae3ac8fd9983861a6f2acafdedfae82eb9e34e
|
7
|
+
data.tar.gz: a0b899888438ae57a78b170be5bd545c6924f6a8db903c4f5eba3be86e5b4d5967aeab443807e1e8a23c7a036b16fa51750db27a80c87b79471d7d9c01db7a2a
|
data/Gemfile.lock
CHANGED
data/lib/rya/core_extensions.rb
CHANGED
@@ -1,6 +1,36 @@
|
|
1
1
|
module Rya
|
2
2
|
# Contains extensions to core Ruby classes and modules.
|
3
|
+
|
3
4
|
module CoreExtensions
|
5
|
+
module Array
|
6
|
+
# Scales with respect to the min and max of the data actually in the Array.
|
7
|
+
def scale new_min, new_max
|
8
|
+
old_min = self.min
|
9
|
+
old_max = self.max
|
10
|
+
|
11
|
+
self.scale_fixed old_min, old_max, new_min, new_max
|
12
|
+
end
|
13
|
+
|
14
|
+
# Scales with respect to a fixed old_min and old_max
|
15
|
+
def scale_fixed old_min, old_max, new_min, new_max
|
16
|
+
self.map do |elem|
|
17
|
+
Rya::ExtendedClasses::MATH.scale elem, old_min, old_max, new_min, new_max
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Math
|
23
|
+
def scale val, old_min, old_max, new_min, new_max
|
24
|
+
# This can happen if you use the mean across non-zero samples.
|
25
|
+
if old_max - old_min == 0
|
26
|
+
# TODO better default value than this?
|
27
|
+
(new_min + new_max) / 2;
|
28
|
+
else
|
29
|
+
((((new_max - new_min) * (val - old_min)) / (old_max - old_min).to_f) + new_min)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
4
34
|
|
5
35
|
module Time
|
6
36
|
# Nicely format date and time
|
@@ -85,4 +115,12 @@ module Rya
|
|
85
115
|
end
|
86
116
|
end
|
87
117
|
end
|
88
|
-
end
|
118
|
+
end
|
119
|
+
|
120
|
+
module Rya
|
121
|
+
# Mainly for external use within the CoreExtensions module definitions
|
122
|
+
module ExtendedClasses
|
123
|
+
MATH = Class.new.extend(Rya::CoreExtensions::Math)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
data/lib/rya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|