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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4bdefcc4ff87903fed556272a44c7af65c0c68108afcb10b44aef7bc276a4cd
4
- data.tar.gz: 69e8d7f5bb010371caccabe8839ca9768010ae80a030fe746dab7d893bc917f7
3
+ metadata.gz: c1b60bb4be1d46a063d19d7c10b24ca53e82e9861a12c91548bd27750fe3d4c9
4
+ data.tar.gz: 8a1c7dc60abe41dc5d544abc66cf207005f51fe2786e6b1734f178e12a8316fe
5
5
  SHA512:
6
- metadata.gz: a5b044b625e0c7d055bac3dda679a5beade14ff2bc2e898ba7c6faa6cd1b5d6e28ca235f564105e8fe2aeba26488dcaf8e3c3a7d513a919938aeaa98d23d0153
7
- data.tar.gz: a0080228a81c072b97bf51b165776ad8820fd44ccfb9c0a6c7dbe7910d2d450dcd89cb07dd5fd8432c356c5303a085c1156700365c621768d8c57dd9e87d58ed
6
+ metadata.gz: 37a6f09b84d3d71ebf5fbf1d95cfabd639186c67f67159731383b2d5f1298fdc4480bb9ab46d25b95a3a873d21ea9f8c832340ba86c055e49b6d5700d89ec990
7
+ data.tar.gz: 5c57b0de2b0481cdc4776ea0e3a03f89d4d70e82c8241a7caca2b76cf76e3cd3d88fd0b33648262cc110ff85f3b95a16e12e8966c669b6fb6d6138210e0e9f86
@@ -6,4 +6,5 @@ end
6
6
 
7
7
  %w(
8
8
  pitch_class
9
+ meter
9
10
  ).each { |f| require File.join(Mext::MUSIC_PATH, f) }
@@ -1,5 +1,5 @@
1
1
  module Mext
2
- module Numeric
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::Numeric::Meter.new(n,d)
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
@@ -24,7 +24,6 @@ module Mext
24
24
  NON_VECTORIZABLE_METHODS = %w(
25
25
  constants
26
26
  pitch_fork
27
- meter
28
27
  )
29
28
  ADDED_METHODS = NON_VECTORIZABLE_METHODS + VECTORIZABLE_METHODS
30
29
 
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.21.2'
2
+ VERSION = '0.21.3'
3
3
  end
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.2
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