rya 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ef55a737eaebe85c9393d5402f42e7bda62be7e
4
- data.tar.gz: a8e9ad77e1f77c719527cfa52106ed01d6167755
3
+ metadata.gz: f0598dd96f2bf67601ec24f16e84d13f7e5f8c1c
4
+ data.tar.gz: 57cf0d5cdf6033ceae57e9639784a166d0d9257f
5
5
  SHA512:
6
- metadata.gz: 76374a6b9e8b951f06cd9091dac5159dcd8e6aacb35d5837a519f97df35d67357ff9ce2d4ed4cb1d0fa243502f492385c9547517f8e79826aecd60b18e73ed06
7
- data.tar.gz: 9251f4d8a451ad0bac45e9f8f08fa37bee9f56ceacccc96929749c7ae5d47963fc1411af18782f112245ba3cca42e4a01c6a0728400bf1f6a5251d6389aa461a
6
+ metadata.gz: d9fd3046fdbc13045f55959d002634eabbe21c551237709a0af24e9668a82d776e55a42356b9606845ddf30f59ae3ac8fd9983861a6f2acafdedfae82eb9e34e
7
+ data.tar.gz: a0b899888438ae57a78b170be5bd545c6924f6a8db903c4f5eba3be86e5b4d5967aeab443807e1e8a23c7a036b16fa51750db27a80c87b79471d7d9c01db7a2a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rya (0.2.0)
4
+ rya (0.3.0)
5
5
  abort_if (~> 0.2.0)
6
6
  systemu (~> 2.6, >= 2.6.5)
7
7
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rya
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-28 00:00:00.000000000 Z
11
+ date: 2018-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler