Class: Webern::Row

Inherits:
Array
  • Object
show all
Defined in:
lib/webern/row.rb

Instance Method Summary collapse

Methods inherited from Array

#generate_row_from_letters, #is_all_integers?

Constructor Details

#initialize(*_row) ⇒ Row

Returns a new instance of Row



3
4
5
6
7
8
9
# File 'lib/webern/row.rb', line 3

def initialize(*_row)
  @row = _row
  check_for_valid_row(@row)
  @row = process_strings if @row.any?{|element| element.is_a?(String) }
  @row = complete_row[0..11]
  replace @row
end

Instance Method Details

#check_for_valid_row(elements) ⇒ Object

Raises:



37
38
39
# File 'lib/webern/row.rb', line 37

def check_for_valid_row(elements)
  raise InvalidRow unless row_is_valid_numbers? or row_is_strings?
end

#complete_rowObject



25
26
27
28
29
# File 'lib/webern/row.rb', line 25

def complete_row
  return @row if @row.size == 12
  _remainder = Array(0..11) - @row
  [@row, _remainder].flatten
end

#inversionObject



13
14
15
# File 'lib/webern/row.rb', line 13

def inversion
  Row.new *map{|note| (12 - note) % 12 }
end

#process_stringsObject



31
32
33
34
35
# File 'lib/webern/row.rb', line 31

def process_strings
  full_string = @row.join("").split("")
  _letters = full_string.uniq[0..11]
  _letters.generate_row_from_letters
end

#retrogradeObject



11
# File 'lib/webern/row.rb', line 11

def retrograde; Row.new *reverse; end

#retrograde_inversionObject



17
18
19
# File 'lib/webern/row.rb', line 17

def retrograde_inversion
  Row.new *inversion.retrograde
end

#row_is_strings?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/webern/row.rb', line 45

def row_is_strings?
  @row.all?{|element| element.is_a?(String) }
end

#row_is_valid_numbers?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/webern/row.rb', line 41

def row_is_valid_numbers?
  @row.all?{|element| element.is_a?(Fixnum) } and (@row - Array(0..11)).empty?
end

#transpose(interval) ⇒ Object



21
22
23
# File 'lib/webern/row.rb', line 21

def transpose(interval)
  Row.new *map{|note| (note + interval) % 12 }
end

#zero_rowObject



49
50
51
# File 'lib/webern/row.rb', line 49

def zero_row
  transpose(12-self[0])
end