Sha256: c5653cc7139866a6b2492c524b1dcaa55b6074f205a2dcfde1468cd9292e1ac2
Contents?: true
Size: 863 Bytes
Versions: 1
Compression:
Stored size: 863 Bytes
Contents
# frozen_string_literal: true module Coltrane class Frequency attr_reader :frequency def initialize(frequency) @frequency = frequency.to_f end class << self alias [] new end def to_s "#{frequency}hz" end def to_f frequency end def octave(n) Frequency[frequency * 2**n] end def ==(other) frequency == (other.is_a?(Frequency) ? other.frequency : other) end def octave_up(n = 1) octave(n) end def octave_down(n = 1) octave(-n) end def /(other) case other when Frequency then FrequencyInterval[1200 * Math.log2(other.frequency / frequency)] when Numeric then Frequency[frequency / other] end end def method_missing(method, *args) Frequency[frequency.send(method, args[0].to_f)] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
coltrane-2.2.1 | lib/coltrane/frequency.rb |