Class: Coltrane::Commands::FindScale

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

Constant Summary

Constants inherited from Command

Command::COMMON_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(scale_set) ⇒ FindScale

Returns a new instance of FindScale.



6
7
8
# File 'lib/coltrane/commands/find_scale.rb', line 6

def initialize(scale_set)
  @scale_set = scale_set
end

Instance Attribute Details

#scale_setObject (readonly)

Returns the value of attribute scale_set.



4
5
6
# File 'lib/coltrane/commands/find_scale.rb', line 4

def scale_set
  @scale_set
end

Class Method Details

.mercenary_init(program) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/coltrane/commands/find_scale.rb', line 14

def self.mercenary_init(program)
  program.command(:'find-scale') do |c|
    c.syntax 'find-scale --notes C-D-E-...] OR --chord Cmaj7-Db7'
    c.description 'finds scales with the provided --notes or --chord'
    c.option :notes, '--notes C-D-E', 'Find scales with those notes'
    c.option :chords, '--chords Cmaj7-D11', 'find scales with those chords'
    c.action do |(_), notes: nil, chords: nil|
      begin
        if notes
          Theory::Scale.having_notes(
            Theory::NoteSet[*notes.to_s.split('-')]
          )
        elsif chords
          Theory::Scale.having_chords(*chords.to_s.split('-'))
        else
          raise 'Provide --notes or --chords separated by dashes.' \
                'For example coltrane find-scale --notes C-E-F#'
        end
      end
      .yield_self { |scale_set| new(scale_set).render }
    end
  end
end

Instance Method Details

#representationObject



10
11
12
# File 'lib/coltrane/commands/find_scale.rb', line 10

def representation
  scale_set
end