Class: Coltrane::Frequency
- Inherits:
-
Object
- Object
- Coltrane::Frequency
show all
- Defined in:
- lib/coltrane/frequency.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(frequency) ⇒ Frequency
Returns a new instance of Frequency.
7
8
9
|
# File 'lib/coltrane/frequency.rb', line 7
def initialize(frequency)
@frequency = frequency.to_f
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
46
47
48
|
# File 'lib/coltrane/frequency.rb', line 46
def method_missing(method, *args)
Frequency[frequency.send(method, args[0].to_f)]
end
|
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
5
6
7
|
# File 'lib/coltrane/frequency.rb', line 5
def frequency
@frequency
end
|
Instance Method Details
#/(other) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/coltrane/frequency.rb', line 39
def /(other)
case other
when Frequency then Interval[1200 * Math.log2(frequency / other.frequency)]
when Numeric then Frequency[frequency / other]
end
end
|
#==(other) ⇒ Object
27
28
29
|
# File 'lib/coltrane/frequency.rb', line 27
def ==(other)
frequency == (other.is_a?(Frequency) ? other.frequency : other)
end
|
#octave(n) ⇒ Object
23
24
25
|
# File 'lib/coltrane/frequency.rb', line 23
def octave(n)
frequency * 2**n
end
|
#octave_down(n = 1) ⇒ Object
35
36
37
|
# File 'lib/coltrane/frequency.rb', line 35
def octave_down(n = 1)
octave(-n)
end
|
#octave_up(n = 1) ⇒ Object
31
32
33
|
# File 'lib/coltrane/frequency.rb', line 31
def octave_up(n = 1)
octave(n)
end
|
#to_f ⇒ Object
19
20
21
|
# File 'lib/coltrane/frequency.rb', line 19
def to_f
frequency
end
|
#to_s ⇒ Object
15
16
17
|
# File 'lib/coltrane/frequency.rb', line 15
def to_s
"#{frequency}hz"
end
|