artoo 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/artoo/ext/numeric.rb +22 -3
- data/lib/artoo/version.rb +1 -1
- data/test/ext/numeric_test.rb +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4a98d6ea130561bdfb378ba49cbc66a804d20cc
|
4
|
+
data.tar.gz: c69a8eccf219e3dab754bfc588ab2981f550a97e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74f36dc3deb8f323b037c217c8507484c3d3d128e9e94f9e744974494a93692423613a7a2fe1ba7ee800a43ccb7f852272bd383b01e255f9c3f21e6531531041
|
7
|
+
data.tar.gz: 651037f50a9cab9950c680e9f3af964e794699eeb0b427aa61014064f95f738278f183c2196a4467e31bb8fbbdbebf2a2730be2d73561fb2f14b94a21a007e8e
|
data/Gemfile.lock
CHANGED
data/lib/artoo/ext/numeric.rb
CHANGED
@@ -24,9 +24,28 @@ class Fixnum
|
|
24
24
|
def to_pwm_reverse
|
25
25
|
((255.0 / 1023.0) * (1023 - self.to_f)).round
|
26
26
|
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Numeric
|
30
|
+
# convert value from old scale (min to max) to (0..1) scale
|
31
|
+
def from_scale(range)
|
32
|
+
(self.to_f - range.min) / (range.max - range.min)
|
33
|
+
end
|
34
|
+
|
35
|
+
# convert value from (0..1) scale to new (min to max) scale
|
36
|
+
def to_scale(range)
|
37
|
+
((self.to_f * (range.max - range.min) + range.min).ceil).within(range)
|
38
|
+
end
|
27
39
|
|
28
|
-
#
|
29
|
-
def
|
30
|
-
|
40
|
+
# keep returned value absolutely within range
|
41
|
+
def within(range)
|
42
|
+
case
|
43
|
+
when self < range.min
|
44
|
+
range.min
|
45
|
+
when self > range.max
|
46
|
+
range.max
|
47
|
+
else
|
48
|
+
self
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|
data/lib/artoo/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
it "#second" do
|
5
|
+
1.second.must_equal 1
|
6
|
+
end
|
7
|
+
|
8
|
+
it "#seconds" do
|
9
|
+
20.seconds.must_equal 20
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Numeric do
|
14
|
+
it "#to_scale with Integer" do
|
15
|
+
2.from_scale(1..10).to_scale(1..20).must_equal 4
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#to_scale with angle" do
|
19
|
+
90.from_scale(0..180).to_scale(-90..90).must_equal 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "#to_scale with angle" do
|
23
|
+
45.from_scale(0..180).to_scale(0..90).must_equal 23
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#to_scale with Float" do
|
27
|
+
x = 2.5
|
28
|
+
x.from_scale(1..10).to_scale(1..20).must_equal 5
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Fixnum do
|
33
|
+
it "#to_pwm"
|
34
|
+
it "#to_pwm_reverse"
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Evans
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-09-
|
15
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: celluloid
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- test/delegator_test.rb
|
252
252
|
- test/device_test.rb
|
253
253
|
- test/drivers/driver_test.rb
|
254
|
+
- test/ext/numeric_test.rb
|
254
255
|
- test/master_test.rb
|
255
256
|
- test/port_test.rb
|
256
257
|
- test/robot_test.rb
|