Module: Interrogative::BaseMethods

Included in:
ClassMethods, InstanceMethods
Defined in:
lib/interrogative.rb

Overview

Methods applicable on both the class and instance levels.

Instance Method Summary collapse

Instance Method Details

#postprocess_question(question) ⇒ Question

Run the defined postprocessors on the given question.

Useful when you need to postprocess questions at a higher level.

Parameters:

Returns:



22
23
24
25
26
27
28
29
# File 'lib/interrogative.rb', line 22

def postprocess_question(question)
  unless @_question_postprocessors.nil?
    @_question_postprocessors.each do |postprocessor|
      postprocessor.call(question)
    end
  end
  question
end

#question(name, text, attrs = {}, &instance_block) ⇒ Question

Give a new question.

Parameters:

  • name (Symbol, String)

    the name (think <input name=...>) of the question.

  • label (String)

    the text of the question (think <label>).

  • attrs (Hash) (defaults to: {})

    additional attributes for the question.

  • instance_block (Proc)

    a block returning option values.

Options Hash (attrs):

  • :long (Boolean)

    whether the question has a long answer (think <textarea> vs <input>).

  • :multiple (Boolean)

    whether the question could have multiple answers.

Returns:

See Also:



44
45
46
47
48
49
50
# File 'lib/interrogative.rb', line 44

def question(name, text, attrs={}, &instance_block)
  q = Question.new(name, text, self, attrs, &instance_block)
  (@_questions||=[]) << q
  
  postprocess_question(q)
  return q
end

#when_questioned(&postprocessor) ⇒ Object

Give instructions for dealing with new questions.

Parameters:

  • postprocessor (Proc)

    a block to run after adding a question; the question is given as the argument.



12
13
14
# File 'lib/interrogative.rb', line 12

def when_questioned(&postprocessor)
  (@_question_postprocessors||=[]) << postprocessor unless postprocessor.nil?
end