Skip to content

Commit

Permalink
Update verbose logic with ternary operators
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmacphersonmusic committed May 26, 2015
1 parent df33826 commit 775d14e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
15 changes: 2 additions & 13 deletions lib/music_theory/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class Note
attr_accessor :frequency, :pitch, :duration, :output_file_name, :distort

def initialize(options = {})
@frequency = options[:frequency] || 440.0 # Note frequency in Hz
@pitch = options[:pitch] # ex: Pitch.new(:Fs, 4) -> (pitch, octave)
@frequency = evaluate_frequency
@frequency = options[:pitch] ? options[:pitch].frequency
: options[:frequency].to_f || 440 # pitch ex) Pitch.new(:Ds, 3)
@duration = options[:duration] || 1.0 # Number of seconds per note
@distort = options[:distort] || false
@output_file_name = options[:output_file_name] || 'note' # File name to write (without extension)
Expand Down Expand Up @@ -54,15 +53,5 @@ def distort!(samples)
sample /= 8.to_f
end
end

private

def evaluate_frequency
if @pitch
@pitch.frequency
else
@frequency.to_f
end
end
end
end
6 changes: 1 addition & 5 deletions lib/music_theory/pitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def replace_sharp_or_flat(note)

def prepare_note_for_offset_map(note)
letter = note[0].upcase
accidental = if note[1] then
note[1].downcase
else
""
end
accidental = note[1] ? note[1].downcase : ""
"#{letter}#{accidental}".to_sym
end
end

0 comments on commit 775d14e

Please sign in to comment.