Sha256: 72e477a4bd5f8600837f31133c378543ed68cd2d1af457baed92966b3269688c

Contents?: true

Size: 680 Bytes

Versions: 3

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

module Prompts
  class ConfirmPrompt < Prompt
    def initialize(...)
      super

      @prompt = if @default == false
        "Choose [y/N]:"
      elsif @default == true
        "Choose [Y/n]:"
      else
        "Choose [y/n]:"
      end
      @default_boolean = @default
      @default = nil
      @instructions = "Press Enter to submit"
      @validations << ->(choice) { "Invalid choice." if !["y", "n", "Y", "N", ""].include?(choice) }
    end

    private

    def resolve_choice_from(response)
      case response
      when "y", "Y" then true
      when "n", "N" then false
      when "" then @default_boolean
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prompts-0.3.1 lib/prompts/confirm_prompt.rb
prompts-0.3.0 lib/prompts/confirm_prompt.rb
prompts-0.2.1 lib/prompts/confirm_prompt.rb