ruby-mext 0.21.2 → 0.21.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mext/music.rb +1 -0
- data/lib/mext/{numeric → music}/meter.rb +37 -2
- data/lib/mext/numeric.rb +0 -1
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1b60bb4be1d46a063d19d7c10b24ca53e82e9861a12c91548bd27750fe3d4c9
|
4
|
+
data.tar.gz: 8a1c7dc60abe41dc5d544abc66cf207005f51fe2786e6b1734f178e12a8316fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a6f09b84d3d71ebf5fbf1d95cfabd639186c67f67159731383b2d5f1298fdc4480bb9ab46d25b95a3a873d21ea9f8c832340ba86c055e49b6d5700d89ec990
|
7
|
+
data.tar.gz: 5c57b0de2b0481cdc4776ea0e3a03f89d4d70e82c8241a7caca2b76cf76e3cd3d88fd0b33648262cc110ff85f3b95a16e12e8966c669b6fb6d6138210e0e9f86
|
data/lib/mext/music.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Mext
|
2
|
-
module
|
2
|
+
module Music
|
3
3
|
|
4
4
|
#
|
5
5
|
# +Meter+:
|
@@ -20,6 +20,7 @@ module Mext
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_r
|
23
|
+
raise ZeroDivisionError, "#{self.numerator}/#{self.divisor} provokes a zero-division error" unless self.divisor != 0
|
23
24
|
Rational(self.numerator, self.divisor)
|
24
25
|
end
|
25
26
|
|
@@ -30,6 +31,11 @@ module Mext
|
|
30
31
|
# we use the logic of +Rational+ to perform logic on +Meter+
|
31
32
|
#
|
32
33
|
[:==, :<, :<=, :>, :>=, :<=>, :===].each { |m| define_method(m) { |other| common_logic(m, other) } }
|
34
|
+
#
|
35
|
+
# we use the arithmetic of +Rational+ to perform arithmetic on +Meter+
|
36
|
+
#
|
37
|
+
[:+, :-, :*, :/, :**, :^, ].each { |m| define_method(m) { |other| common_arithmetic(m, other) } }
|
38
|
+
|
33
39
|
|
34
40
|
private
|
35
41
|
|
@@ -37,6 +43,10 @@ module Mext
|
|
37
43
|
raise ArgumentError, "#{other} is neither a #{self.class} nor a Rational (#{other.class})" unless other.kind_of?(Meter) || other.kind_of?(Rational)
|
38
44
|
self.to_r.send(method, other.to_r)
|
39
45
|
end
|
46
|
+
|
47
|
+
def common_arithmetic(method, other)
|
48
|
+
self.to_r.send(method, other.to_r).to_meter
|
49
|
+
end
|
40
50
|
|
41
51
|
end
|
42
52
|
|
@@ -47,7 +57,7 @@ end
|
|
47
57
|
# +Meter(n, d)+ is defined to actually mimick a +Rational()+
|
48
58
|
#
|
49
59
|
def Meter(n, d)
|
50
|
-
Mext::
|
60
|
+
Mext::Music::Meter.new(n,d)
|
51
61
|
end
|
52
62
|
|
53
63
|
#
|
@@ -65,3 +75,28 @@ class String
|
|
65
75
|
end
|
66
76
|
|
67
77
|
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# we extend the +Rational+ class to carry a +to_meter+ which
|
81
|
+
# will convert a into a Meter class
|
82
|
+
#
|
83
|
+
class Rational
|
84
|
+
|
85
|
+
def to_meter
|
86
|
+
Meter(self.numerator, self.denominator)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# we extend the +Float+ class to carry a +to_meter+ which
|
93
|
+
# will convert a into a Meter class
|
94
|
+
#
|
95
|
+
class Float
|
96
|
+
|
97
|
+
def to_meter
|
98
|
+
r = self.to_r
|
99
|
+
Meter(r.numerator, r.denominator)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/lib/mext/numeric.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.
|
4
|
+
version: 0.21.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Bernardini
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/mext/math/log.rb
|
160
160
|
- lib/mext/math/stepwise.rb
|
161
161
|
- lib/mext/music.rb
|
162
|
+
- lib/mext/music/meter.rb
|
162
163
|
- lib/mext/music/pitch_class.rb
|
163
164
|
- lib/mext/numeric.rb
|
164
165
|
- lib/mext/numeric/addsemi.rb
|
@@ -169,7 +170,6 @@ files:
|
|
169
170
|
- lib/mext/numeric/dbamp.rb
|
170
171
|
- lib/mext/numeric/ftom.rb
|
171
172
|
- lib/mext/numeric/gold.rb
|
172
|
-
- lib/mext/numeric/meter.rb
|
173
173
|
- lib/mext/numeric/mmtot.rb
|
174
174
|
- lib/mext/numeric/mround.rb
|
175
175
|
- lib/mext/numeric/mtof.rb
|