tonal-tools 1.0.2 → 1.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
  SHA256:
3
- metadata.gz: bc35954dbfa03dfe0acca0efda8508d06cffc3259fd7f9d959ff260e099c2de5
4
- data.tar.gz: 1de6de9804f88b954ec67720e5b29a3de83a6c6d49577de5a679745b5f4491ab
3
+ metadata.gz: 496a1287b6645e141aae7b35adadb77a1a9add394a92921c69aa7d5fb2f69c95
4
+ data.tar.gz: 49c8251e9bbc99f352042d6184accb916d81c1b22a09a1d296268203e0f759df
5
5
  SHA512:
6
- metadata.gz: 4f9cd04eab65b20ddf0263910c661337c6a02d47ebabc5277eeaf7358e686f38283d1158ef985ee238625330b338acca9090021d22c10128d92955b3d5f59891
7
- data.tar.gz: '0858ee0672ee37381878371622d7b46471341e56e7c85bceae5c447a3112199330d59931f5ba070fb5a82d6fd9e1e42d8f66838edb229707c9afbdadb13222cd'
6
+ metadata.gz: 998647702008bf98462b2e246a868649906348c083563c1e537ead89cccacb4fccf4f2125d3aad79137f1b37ae2b7e5371132fe720ad1e5013c5f638b1e6c4a9
7
+ data.tar.gz: 64faa5fb6347d5259fb803e7627a1469fa0d1ae154852ccaad11be9f33371f5ac73b0ea30de2a4eaf40d96699037ea4b519e2cfa9f1b8f845590d123449d6b75
data/lib/tonal/cents.rb CHANGED
@@ -68,7 +68,7 @@ class Tonal::Cents
68
68
  end
69
69
 
70
70
  # @return
71
- # [Cents] nearest hundredth cent difference
71
+ # [Tonal::Cents] nearest hundredth cent difference
72
72
  # @example
73
73
  # Tonal::Cents.new(701.9550008653874).nearest_hundredth_difference => 1.955000865387433
74
74
  #
@@ -76,7 +76,10 @@ class Tonal::Cents
76
76
  self.class.new(cents: (value - nearest_hundredth))
77
77
  end
78
78
 
79
- # TODO: Document or Consider if needed
79
+ # @return [Array] a tuple of self offset positively/negatively by limit
80
+ # @example
81
+ # Tonal::Cents.new(cents: 100.0).plus_minus
82
+ # => [95.0, 105.0]
80
83
  #
81
84
  def plus_minus(limit = 5)
82
85
  [self - limit, self + limit]
@@ -133,11 +136,6 @@ class Tonal::Cents
133
136
  case result
134
137
  when Numeric
135
138
  self.class.new(cents: result)
136
- # TODO: Work this case out or remove
137
- #when Array
138
- # result.collect do |e|
139
- # e.kind_of?(Numeric) ? Cents.new(e) : e
140
- # end
141
139
  else
142
140
  result
143
141
  end
@@ -11,7 +11,7 @@ class Prime
11
11
  end
12
12
 
13
13
  class Numeric
14
- # @return [Array], a tuple of self offset positively/negatively
14
+ # @return [Array] a tuple of self offset positively/negatively
15
15
  # @example
16
16
  # Math::PI.plus_minus(3)
17
17
  # => [6.141592653589793, 0.14159265358979312]
@@ -74,7 +74,7 @@ class Numeric
74
74
 
75
75
  # @return [Tonal::Cents] of self interpreted as a ratio
76
76
  # @example
77
- # (3/2r).cents => 701.96
77
+ # (3/2r).to_cents => 701.96
78
78
  #
79
79
  def to_cents
80
80
  self.log2.to_cents
@@ -371,8 +371,9 @@ class Array
371
371
  end
372
372
  alias :vector :to_vector
373
373
 
374
- # @return [Integer] least common multiple of elements of self
375
- # @example TODO
374
+ # @return [Integer] least common multiple of integer elements of self
375
+ # @example
376
+ # [3, 2, 7].lcm => 42
376
377
  #
377
378
  def lcm
378
379
  self.reduce(1, :lcm)
@@ -414,11 +415,6 @@ class Array
414
415
  end
415
416
  alias :cents :to_cents
416
417
 
417
- # TODO: Consider removing
418
- #def cons_diff(cons=2)
419
- # self.each_cons(cons).map{|a,b| (a - b).abs }
420
- #end
421
-
422
418
  # @return [Float] the mean of the elements of self
423
419
  # @example
424
420
  # [1, 2].mean => 1.5
data/lib/tonal/log.rb CHANGED
@@ -15,6 +15,8 @@ class Tonal::Log
15
15
  #
16
16
  def initialize(logarithmand: nil, logarithm: nil, base: nil)
17
17
  raise ArgumentError, "logarithmand or logarithm must be provided" if logarithmand.nil? && logarithm.nil?
18
+ raise ArgumentError, "logarithmand must be Numeric" unless logarithmand.kind_of?(Numeric) || logarithmand.nil?
19
+ raise ArgumentError, "logarithm must be Numeric" unless logarithm.kind_of?(Numeric) || logarithm.nil?
18
20
 
19
21
  if logarithmand && logarithm && base
20
22
  @logarithmand = logarithmand
@@ -97,8 +99,6 @@ class Tonal::Log
97
99
  end
98
100
  end
99
101
 
100
- # TODO Explain how this works
101
- #
102
102
  def method_missing(op, *args, &blk)
103
103
  rhs = args.collect do |arg|
104
104
  arg.kind_of?(self.class) ? arg.inspect : arg
@@ -108,11 +108,6 @@ class Tonal::Log
108
108
  case result
109
109
  when Numeric
110
110
  self.class.new(result)
111
- # Work this case out
112
- #when Array
113
- # result.collect do |e|
114
- # e.kind_of?(Numeric) ? Cents.new(e) : e
115
- # end
116
111
  else
117
112
  result
118
113
  end
data/lib/tonal/ratio.rb CHANGED
@@ -147,7 +147,7 @@ class Tonal::Ratio
147
147
  # @param base
148
148
  #
149
149
  def to_log(base=2)
150
- Tonal::Log.new(logarithmand: self, base: base)
150
+ Tonal::Log.new(logarithmand: to_r, base: base)
151
151
  end
152
152
  alias :log :to_log
153
153
 
@@ -156,7 +156,7 @@ class Tonal::Ratio
156
156
  # Tonal::ReducedRatio.new(3,2).to_log2 => 0.5849625007211562
157
157
  #
158
158
  def to_log2
159
- Tonal::Log2.new(logarithmand: self)
159
+ Tonal::Log2.new(logarithmand: to_r)
160
160
  end
161
161
  alias :log2 :to_log2
162
162
 
@@ -165,7 +165,7 @@ class Tonal::Ratio
165
165
  # Tonal::Ratio.new(3,2).to_cents => 701.96
166
166
  #
167
167
  def to_cents
168
- Tonal::Cents.new(ratio: self)
168
+ Tonal::Cents.new(ratio: to_r)
169
169
  end
170
170
  alias :cents :to_cents
171
171
 
@@ -255,16 +255,19 @@ class Tonal::Ratio
255
255
  self
256
256
  end
257
257
 
258
- # @return [Tonal::ReducedRatio] the mirror of self along the axis (default 1/1)
258
+ # @return [Tonal::Ratio] the mirror of self along the axis (default 1/1)
259
259
  # @example
260
- # Tonal::ReducedRatio.new(4,3).mirror => (3/2)
260
+ # Tonal::Ratio.new(4,3).mirror => (3/2)
261
261
  # @param axis
262
262
  #
263
263
  def mirror(axis=1/1r)
264
264
  (self.class.new(axis) ** 2) / self
265
265
  end
266
266
 
267
- # TODO: Justify or remove
267
+ # @return [Tonal::Ratio]
268
+ # @example
269
+ # Tonal::Ratio.new(4/3r).mirror2(4/2r) => (3/8)
270
+ # @param ratio
268
271
  #
269
272
  def mirror2(ratio)
270
273
  self.class.new(invert.to_r / ratio)
data/lib/tonal/step.rb CHANGED
@@ -36,7 +36,7 @@ class Tonal::Step
36
36
  ratio.to_r
37
37
  end
38
38
 
39
- def cents
39
+ def to_cents
40
40
  ratio.to_cents
41
41
  end
42
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tonal-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml
@@ -183,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - ">="
185
185
  - !ruby/object:Gem::Version
186
- version: 3.1.2
186
+ version: '3.1'
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
190
190
  - !ruby/object:Gem::Version
191
191
  version: '3.1'
192
192
  requirements: []
193
- rubygems_version: 3.4.22
193
+ rubygems_version: 3.5.1
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: Tonal tools