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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de6e726dc7a4d253d4acfb870173fd4928a8734c
4
- data.tar.gz: f6ede2be821e79a2711f6f0cb8f67e5d511ce706
3
+ metadata.gz: f4a98d6ea130561bdfb378ba49cbc66a804d20cc
4
+ data.tar.gz: c69a8eccf219e3dab754bfc588ab2981f550a97e
5
5
  SHA512:
6
- metadata.gz: 247a5ea51e36972fdab99d623f74089d6ed66fc6ad43aa400055cb7a0ea3d4229b21c577fe702b35a5c83b0ead2ea15641df1ff525b9773b931898122c7e75d6
7
- data.tar.gz: 00b1db0bf425d8519bfc5efb30e64c71f5dfcc34898122a7acdd4f15c5930215b8c94336c8eea492fd9149500b356cd02faa8cc40f401ccb253e4a0bd1c9cc9e
6
+ metadata.gz: 74f36dc3deb8f323b037c217c8507484c3d3d128e9e94f9e744974494a93692423613a7a2fe1ba7ee800a43ccb7f852272bd383b01e255f9c3f21e6531531041
7
+ data.tar.gz: 651037f50a9cab9950c680e9f3af964e794699eeb0b427aa61014064f95f738278f183c2196a4467e31bb8fbbdbebf2a2730be2d73561fb2f14b94a21a007e8e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo (1.2.0)
4
+ artoo (1.2.1)
5
5
  celluloid (~> 0.15.0)
6
6
  celluloid-io (~> 0.15.0)
7
7
  multi_json (~> 1.6)
@@ -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
- # convert value from old scale (min to max) to new scale (0 to new_max)
29
- def to_scale(min, max, new_scale)
30
- (((self.to_f - min) / (max - min)) * new_max).round
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
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
@@ -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.0
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-17 00:00:00.000000000 Z
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