Sha256: 6425bafb757516762eb46938064c3ad5b8ba60322597137b285a9d59dbde63d0

Contents?: true

Size: 763 Bytes

Versions: 6

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

require_relative 'question'

class HighlineWrapper
  class OpenEndedQuestion < Question
    class << self
      def ask(prompt, options)
        answer = ask_highline(prompt, secret: options[:secret]).to_s

        return answer unless answer.empty?
        return recurse(prompt, nil, options) if options[:required]

        print_default_message(options) if options[:indicate_default_message]
        options[:default]
      end

      private def print_default_message(options)
        if !options[:secret]
          puts "--- Default selected: #{options[:default].empty? ? 'EMPTY' : options[:default]} ---"
        elsif options[:secret]
          puts '--- Default selected: HIDDEN ---'
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
highline_wrapper-1.3.1 lib/highline_wrapper/open_ended_question.rb
highline_wrapper-1.3.0 lib/highline_wrapper/open_ended_question.rb
highline_wrapper-1.2.2 lib/highline_wrapper/open_ended_question.rb
highline_wrapper-1.2.1 lib/highline_wrapper/open_ended_question.rb
highline_wrapper-1.2.0 lib/highline_wrapper/open_ended_question.rb
highline_wrapper-1.1.0 lib/highline_wrapper/open_ended_question.rb