analog 0.2 → 0.3

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: 5fa67d3ea0f497fdb0f6c4e0d795d539963f4b09
4
- data.tar.gz: deed6727fb227a1f7f59efd3b6ac09d3c915ea52
3
+ metadata.gz: d51400d28d570348eff96771885c19af401f4cf5
4
+ data.tar.gz: 4d7926c87476b2057ae901f7baeb65a6b969bef8
5
5
  SHA512:
6
- metadata.gz: 49e2004c03e8cbc8288feff90b472efca61cfc5dc84c9df5cbcdadaed0b5d9ead6ae231056f7919af3d56784a7198d8711294bfdeb95fcbeb3a645d1e15f59dd
7
- data.tar.gz: 0ecb3626a87261d3d6c5c693a83420d000df25158a16ef055e89fef2d846d9244519b9afa8e1d80b2944ecb6b0221fbcec408c404d57c7c6ff3510e4e79089cc
6
+ metadata.gz: 749cb1957e2a5c79b9177cf0d19baeee45fec89abd5d2d60630314d231bb76124e213a8fe9da54475fb39a6e675b84ad653e8dd4f3fed8ef2ee1a3799b7469e9
7
+ data.tar.gz: 4b7a657eec352c1b81dbd877aad80585a4a4180c62994c57e38463752cfe85f50da552fa5c7f0a2abedec141e74b20669fb7b2f11ccbac340b25a0ed359bcd6d
data/lib/scale.rb CHANGED
@@ -6,6 +6,6 @@ require "scale/source"
6
6
  # A Ruby helper for scaling numbers
7
7
  module Scale
8
8
 
9
- VERSION = "0.2"
9
+ VERSION = "0.3"
10
10
 
11
11
  end
data/lib/scale/scheme.rb CHANGED
@@ -1,23 +1,26 @@
1
1
  module Scale
2
2
 
3
+ extend self
4
+
3
5
  # Build a scaling scheme for the given input
4
6
  # @param [Numeric] input
5
7
  # @return [Scale::Scheme]
6
- def self.transform(input)
8
+ def transform(input)
7
9
  Scheme.new.scale(input)
8
10
  end
11
+ alias_method :scale, :transform
9
12
 
10
13
  # Build a scaling scheme starting with the given source
11
14
  # @param [::Enumerable] source
12
15
  # @return [Scale::Scheme]
13
- def self.from(source)
16
+ def from(source)
14
17
  Scheme.new.from(source)
15
18
  end
16
19
 
17
20
  # Build a scaling scheme starting with the given destination
18
21
  # @param [::Enumerable] destination
19
22
  # @return [Scale::Scheme]
20
- def self.to(destination)
23
+ def to(destination)
21
24
  Scheme.new.to(destination)
22
25
  end
23
26
 
@@ -25,8 +28,8 @@ module Scale
25
28
  # @param [::Enumerable] source
26
29
  # @param [::Enumerable] destination
27
30
  # @return [Scale::Scheme]
28
- def self.using(source, destination)
29
- Scheme.new.using(:source => source, :destination => destination)
31
+ def using(source, destination)
32
+ Scheme.new.using(source, destination)
30
33
  end
31
34
 
32
35
  # Describes a particular scaling scenario
@@ -89,6 +92,7 @@ module Scale
89
92
  @input = number
90
93
  scale? ? result : self
91
94
  end
95
+ alias_method :transform, :scale
92
96
 
93
97
  # Scan this scaling scenario be run?
94
98
  # @return [Boolean] Whether this scaling scenario can be run
@@ -0,0 +1,29 @@
1
+ require "helper"
2
+
3
+ class Scale::DestinationTest < Test::Unit::TestCase
4
+
5
+ context "Destination" do
6
+
7
+ context ".new" do
8
+
9
+ should "recognize a Range" do
10
+ dest = Scale::Destination.new(0..1)
11
+ assert_equal(Scale::Destination::Range, dest.class)
12
+ end
13
+
14
+ should "recognize an Array" do
15
+ dest = Scale::Destination.new([0, 10, 20, 50])
16
+ assert_equal(Scale::Destination::Enumerable, dest.class)
17
+ end
18
+
19
+ should "recognize an Set" do
20
+ dest = Scale::Destination.new(Set.new([0, 10, 20, 50]))
21
+ assert_equal(Scale::Destination::Enumerable, dest.class)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
data/test/scale_test.rb CHANGED
@@ -4,21 +4,7 @@ class ScaleTest < Test::Unit::TestCase
4
4
 
5
5
  context "Scale" do
6
6
 
7
- context "#initialize" do
8
-
9
- should "recognize a Range" do
10
- scheme = Scale::Scheme.new(:source => 0..1, :destination => 0..100)
11
- assert_equal(Scale::Destination::Range, scheme.destination.class)
12
- end
13
-
14
- should "recognize an Array" do
15
- scheme = Scale::Scheme.new(:source => 0..1, :destination => [0, 10, 20, 50])
16
- assert_equal(Scale::Destination::Enumerable, scheme.destination.class)
17
- end
18
-
19
- end
20
-
21
- context "#scale" do
7
+ context "#transform" do
22
8
 
23
9
  should "amplify" do
24
10
  output = Scale.transform(0.10).using(0..1, 0..127)
@@ -0,0 +1,45 @@
1
+ require "helper"
2
+
3
+ class Scale::SchemeTest < Test::Unit::TestCase
4
+
5
+ context "Scheme" do
6
+
7
+ context ".transform" do
8
+
9
+ should "amplify" do
10
+ output = Scale.transform(0.10).using(0..1, 0..127)
11
+ assert_equal(12, output)
12
+ end
13
+
14
+ end
15
+
16
+ context ".from" do
17
+
18
+ should "deamplify" do
19
+ output = Scale.from(0..150).to(0..15).transform(22)
20
+ assert_equal(2, output)
21
+ end
22
+
23
+ end
24
+
25
+ context ".to" do
26
+
27
+ should "scale neg/pos into pos/pos" do
28
+ output = Scale.to(0..3.0).from(-24..24).transform(10)
29
+ assert_equal(2.125, output)
30
+ end
31
+
32
+ end
33
+
34
+ context ".using" do
35
+
36
+ should "scale neg/pos into another neg/pos" do
37
+ output = Scale.using(-24..24, -3..3.0).transform(10)
38
+ assert_equal(1.25, output)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,28 @@
1
+ require "helper"
2
+
3
+ class Scale::SourceTest < Test::Unit::TestCase
4
+
5
+ context "Source" do
6
+
7
+ context ".new" do
8
+
9
+ should "recognize a Range" do
10
+ source = Scale::Source.new(0..1)
11
+ assert_equal(Scale::Source::Range, source.class)
12
+ end
13
+
14
+ should "recognize an Array" do
15
+ source = Scale::Source.new([0, 10, 20, 50])
16
+ assert_equal(Scale::Source::Enumerable, source.class)
17
+ end
18
+
19
+ should "recognize an Set" do
20
+ source = Scale::Source.new(Set.new([0, 10, 20, 50]))
21
+ assert_equal(Scale::Source::Enumerable, source.class)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analog
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
@@ -67,8 +67,11 @@ files:
67
67
  - lib/scale/scheme.rb
68
68
  - lib/scale/source.rb
69
69
  - test/core_ext_test.rb
70
+ - test/destination_test.rb
70
71
  - test/helper.rb
71
72
  - test/scale_test.rb
73
+ - test/scheme_test.rb
74
+ - test/source_test.rb
72
75
  homepage: http://github.com/arirusso/analog
73
76
  licenses:
74
77
  - Apache License (2.0)
@@ -95,4 +98,7 @@ specification_version: 4
95
98
  summary: A Ruby helper for scaling numbers
96
99
  test_files:
97
100
  - test/core_ext_test.rb
101
+ - test/destination_test.rb
98
102
  - test/scale_test.rb
103
+ - test/scheme_test.rb
104
+ - test/source_test.rb