Sha256: 4c18ca05cad30c0b973c4c570305ac0d4a5857364311bba18bd97d0ec5476502

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

module Coltrane
  module Commands
    class Scale < Command
      def representation
        return on_model if on == :text
        { preface => on_model }
      end

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

      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
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coltrane-3.3.0 lib/coltrane/commands/scale.rb
coltrane-3.2.0 lib/coltrane/commands/scale.rb
coltrane-3.1.3 lib/coltrane/commands/scale.rb
coltrane-3.1.2 lib/coltrane/commands/scale.rb
coltrane-3.1.1 lib/coltrane/commands/scale.rb
coltrane-3.1.0 lib/coltrane/commands/scale.rb
coltrane-3.0.0 lib/coltrane/commands/scale.rb