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

- (Row) initialize(*_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

- (Object) check_for_valid_row(elements)

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

- (Object) complete_row



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

- (Object) inversion



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

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

- (Object) process_strings



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

- (Object) retrograde



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

def retrograde; Row.new *reverse; end

- (Object) retrograde_inversion



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

def retrograde_inversion
  Row.new *inversion.retrograde
end

- (Boolean) row_is_strings?



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

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

- (Boolean) row_is_valid_numbers?



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

- (Object) transpose(interval)



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

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

- (Object) zero_row



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

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