Sha256: e8516ee5efde0992df11b7ae7eef1836d3b7af9fabac3c592bfc4e1310d52152

Contents?: true

Size: 854 Bytes

Versions: 3

Compression:

Stored size: 854 Bytes

Contents

require 'forwardable'

module Interactive
  class Question
    extend Forwardable
    attr_accessor :question, :options, :columns
    def_delegators :@question_type, :reask!

    def initialize(&block)
      yield self

      @options = Interactive::Options(Array(@options), @columns)

      raise ArgumentError, "question cannot be nil nor empty." if question.nil? || question.empty?
      if @columns || @options.has_hash?
        @question_type = QuestionWithEagerFullExplanation.new(self)
      else
        @question_type = QuestionWithLazyFullExplanation.new(self)
      end
    end

    def ask_and_wait_for_valid_response(&block)
      @question_type.ask_and_wait_for_valid_response(&block)
    end

    def ask(&block)
      ask_and_wait_for_valid_response(&block)
    end

    private

    def response
      STDIN.gets.chomp
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
interactive-0.6.2 lib/interactive/question.rb
interactive-0.6.1 lib/interactive/question.rb
interactive-0.6.0 lib/interactive/question.rb