Sha256: 2b5e2505823f4e501c092006f380a92f3180c05400d624408cabf033c3ebe606

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Coltrane
  module Cli
    # It manages notes representations, most of times instruments
    class Representation
      ACCEPTED_FLAVORS = %i[marks notes intervals degrees].freeze

      def self.inherited(subclass)
        @@types ||= {}
        @@types[subclass.to_s.split('::').last.underscore.to_sym] = subclass
      end

      def self.build(notes)
        type = Cli.config.on
        raise WrongFlavorError unless ACCEPTED_FLAVORS.include?(Cli.config.flavor)
        raise(WrongRepresentationTypeError, type) unless @@types.include?(type)
        @@types[type].new(notes)
      end

      def initialize(notes)
        @notes    = notes
        @ref_note = notes.first
      end

      def hint
        case Cli.config.flavor
        when :marks then ''
        # when :notes     then "(\u266E means the note is natural, not flat nor sharp)"
        when :intervals
          <<~DESC
            The letters represent the intervals relative to the root tone
            Ex: 1P = Perfect First / 3m = Minor Third / 4A = Augmented Fourth
          DESC

        when :degrees then '(The numbers represent the degree of the note in the scale)'
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
coltrane-3.0.0.rc1 lib/coltrane/commands/representation.rb
coltrane-3.0.0.pre lib/coltrane/commands/representation.rb
coltrane-2.2.1 lib/cli/representation.rb
coltrane-2.1.5 lib/cli/representation.rb
coltrane-2.1.0 lib/cli/representation.rb