Class: Coltrane::Commands::CommonChords

Inherits:
Command
  • Object
show all
Defined in:
lib/coltrane/commands/common_chords.rb

Constant Summary

Constants inherited from Command

Coltrane::Commands::Command::COMMON_OPTIONS

Class Method Summary collapse

Methods inherited from Command

add_shared_option, #custom_guitar, inherited, #render, #renderer_options, subclasses

Class Method Details

.mercenary_init(program) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/coltrane/commands/common_chords.rb', line 12

def self.mercenary_init(program)
  program.command(:'common-chords') do |c|
    c.alias(:'common-chord')
    add_shared_option(:flavor, c)
    add_shared_option(:on, c)
    c.syntax 'common-chords [TONE_1 SCALE_NAME_1], [TONE_2 SCALE_NAME_2], [...]'
    c.description 'Finds chords that are shared between the given scales'
    c.action do |(*scale_strings), **options|
      scale_strings
      .join(' ')
      .split(',')
      .map { |scale_notation|
        Commands::Scale.parse(scale_notation).all_chords
      }
      .reduce(:&)
      .each   { |chord| Commands::Chords.new(chord, **options).render }
    end
  end
end

.parse(scale_notation) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/coltrane/commands/common_chords.rb', line 4

def self.parse(scale_notation)
  scale_notation
  .split(' ', 2)
  .yield_self { |(tone, scale_name)|
    Theory::Scale.fetch(scale_name.gsub(' ', '_'), tone)
  }
end