class Dodecaphony::Row
Attributes
intervals[RW]
original_row[RW]
pitches[R]
Public Class Methods
new(tone_row)
click to toggle source
# File lib/row.rb, line 12 def initialize tone_row self.original_row = create_row_with_pitches(tone_row) validate_size_of original_row self.intervals = create_list_with_intervals(original_row, starting_pitch) end
Public Instance Methods
==(other)
click to toggle source
# File lib/row.rb, line 37 def == other (other.pitches).zip(pitches).all? do |pitches| pitches[0] == pitches[1] end end
each(&block)
click to toggle source
# File lib/row.rb, line 43 def each &block pitches.each &block end
spell_with_flats()
click to toggle source
# File lib/row.rb, line 33 def spell_with_flats normalize_row(:spell_as_flat) end
spell_with_sharps()
click to toggle source
# File lib/row.rb, line 29 def spell_with_sharps normalize_row(:spell_as_sharp) end
to_a()
click to toggle source
# File lib/row.rb, line 23 def to_a pitches.each_with_object([]) do |pitch, row| row << pitch.name end end
to_s()
click to toggle source
# File lib/row.rb, line 19 def to_s to_a.join(" ") end
Private Instance Methods
create_list_with_intervals(row, first_pitch)
click to toggle source
# File lib/row.rb, line 50 def create_list_with_intervals(row, first_pitch) row_list = row.each_with_object({}) do |pitch, hash| distance = first_pitch.distance_from pitch validate_uniqueness_of distance, hash hash[distance] = pitch end finalize_pitches(row_list) end
create_row_with_pitches(tone_row)
click to toggle source
# File lib/row.rb, line 68 def create_row_with_pitches tone_row tone_row.each_with_object([]) do |pitch, row| row << Pitch.new(pitch) end end
finalize_pitches(row_list)
click to toggle source
# File lib/row.rb, line 59 def finalize_pitches(row_list) row_list[12] = starting_pitch row_list end
normalize_row(message)
click to toggle source
# File lib/row.rb, line 87 def normalize_row message original_row.each_with_object([]) do |pitch, row| row << pitch.send(message) end end
starting_pitch()
click to toggle source
# File lib/row.rb, line 64 def starting_pitch original_row[0] end
validate_size_of(row)
click to toggle source
# File lib/row.rb, line 74 def validate_size_of row row_size = row.to_set.length unless row_size == 12 raise ArgumentError, "incorrect number of pitches (#{row_size}) in row" end end
validate_uniqueness_of(distance, hash)
click to toggle source
# File lib/row.rb, line 81 def validate_uniqueness_of distance, hash if hash.has_key? distance raise ArgumentError, "duplicate pitch (#{hash[distance].name})" end end