Class: OutroRails::TransposerController

Inherits:
ApplicationController show all
Includes:
InvalidParamsRedirectable
Defined in:
app/controllers/outro_rails/transposer_controller.rb

Constant Summary collapse

MODES =
%w[chords_to_chords chords_to_nashville nashville_to_chords].freeze
DEFAULT_MODE =
"chords_to_chords"

Instance Method Summary collapse

Instance Method Details

#showObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/outro_rails/transposer_controller.rb', line 12

def show
  @mode = MODES.include?(params[:mode]) ? params[:mode] : DEFAULT_MODE
  @text = params[:text].to_s
  @from_key = Theory::Key.parse(params[:from_key].presence || "C")
  @to_key = Theory::Key.parse(params[:to_key].presence || "C")

  return if @text.blank?

  case @mode
  when "chords_to_chords"
    @result = Theory::Transposer.transpose_chords(@text,
                                                  from: @from_key,
                                                  to: @to_key)
    @semitones = @from_key.interval_to(@to_key)
  when "chords_to_nashville"
    @result = Theory::Transposer.chords_to_nashville(@text, key: @from_key)
  when "nashville_to_chords"
    @result = Theory::Transposer.nashville_to_chords(@text, key: @to_key)
  end
end