Class: Coltrane::Commands::Scale
- Inherits:
-
Command
- Object
- Command
- Coltrane::Commands::Scale
show all
- Defined in:
- lib/coltrane/commands/scale.rb
Constant Summary
Constants inherited
from Command
Command::COMMON_OPTIONS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
add_shared_option, #custom_guitar, inherited, #render, #renderer_options, subclasses
Class Method Details
.mercenary_init(program) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/coltrane/commands/scale.rb', line 17
def self.mercenary_init(program)
program.command(:scale) do |c|
c.syntax 'scale <root_note> <scale name> [--on <instrument>]'
c.description 'Gives you information about a scale. Ex: coltrane scale D Natural Minor --on guitar'
c.option :tertians, '--tertians <SIZE>', 'Outputs all tertian chords from the given size from the scale'
c.option :chords, '--chords [SIZE]', 'Outputs all chords from given size from the scale. Leave size empty to retrieve all'
add_shared_option(:flavor, c)
add_shared_option(:on, c)
add_shared_option(:voicings, c)
c.action { |scale_notation, **options|
parse(scale_notation.join(' '))
.yield_self { |scale|
if options[:tertians]
scale
.tertians(options[:tertians].to_i)
.each { |chord| Commands::Chords.new(chord, **options).render }
elsif options[:chords]
scale.chords(options[:chords].to_i)
.each { |chord| Commands::Chords.new(chord, **options).render }
else
scale.notes
.yield_self {|notes| Commands::Notes.new(notes, **options.merge(preface: scale.full_name)).render }
end
}
}
end
end
|
.parse(scale_notation) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/coltrane/commands/scale.rb', line 9
def self.parse(scale_notation)
scale_notation
.split(' ', 2)
.yield_self { |(tone, scale_name)|
Theory::Scale.fetch(scale_name.gsub(' ', '_'), tone)
}
end
|
Instance Method Details
#representation ⇒ Object
4
5
6
7
|
# File 'lib/coltrane/commands/scale.rb', line 4
def representation
return on_model if on == :text
{ preface => on_model }
end
|