Class: QuestionCollection
- Inherits:
-
Object
- Object
- QuestionCollection
- Defined in:
- app/controllers/surveyor_gui/dependencys_controller.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
QuestionCollection provides a 2 dimensional array consisting of a question id and a question description.
-
#dependency_question_description ⇒ Object
QuestionCollection provides a 2 dimensional array consisting of a question id and a question description.
Instance Method Summary collapse
- #add_question(question) ⇒ Object
- #add_questions(questions) ⇒ Object
-
#initialize(base_question) ⇒ QuestionCollection
constructor
A new instance of QuestionCollection.
Constructor Details
#initialize(base_question) ⇒ QuestionCollection
Returns a new instance of QuestionCollection.
228 229 230 231 232 233 |
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 228 def initialize(base_question) @collection = [] @question_number = 1 @base_question = base_question @dependency_question_description = nil end |
Instance Attribute Details
#collection ⇒ Object
QuestionCollection provides a 2 dimensional array consisting of a question id and a question description. The collection may be used in a view’s select field.
Its membership is determined by a base question. The base question is the one from which other questions in the collection are derived. E.g., in a dependency, the question that is shown or hidden based on the answers to others is the base question. It shouldn’t show up in the collection.
Other questions may or may not show up in the collection depending on their eligibility.
Some questions should have a question number and some should not. The QuestionCollection numbers questions that should be numbered and keeps track of the numbering. If a question is numbered, the question number is included in the description, e.g. “3) What is your name?”. Otherwise, the description is just the question text, e.g. “Don’t forget to use your middle initial”.
Incoming questions may be duck typed, but should respond to is_numbered? and is_eligible? messages.
226 227 228 |
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 226 def collection @collection end |
#dependency_question_description ⇒ Object
QuestionCollection provides a 2 dimensional array consisting of a question id and a question description. The collection may be used in a view’s select field.
Its membership is determined by a base question. The base question is the one from which other questions in the collection are derived. E.g., in a dependency, the question that is shown or hidden based on the answers to others is the base question. It shouldn’t show up in the collection.
Other questions may or may not show up in the collection depending on their eligibility.
Some questions should have a question number and some should not. The QuestionCollection numbers questions that should be numbered and keeps track of the numbering. If a question is numbered, the question number is included in the description, e.g. “3) What is your name?”. Otherwise, the description is just the question text, e.g. “Don’t forget to use your middle initial”.
Incoming questions may be duck typed, but should respond to is_numbered? and is_eligible? messages.
226 227 228 |
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 226 def dependency_question_description @dependency_question_description end |
Instance Method Details
#add_question(question) ⇒ Object
244 245 246 247 248 249 250 |
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 244 def add_question(question) _add_to_collection_if_eligible(question) if question.is_numbered? _increment_question_number end return self end |
#add_questions(questions) ⇒ Object
239 240 241 242 |
# File 'app/controllers/surveyor_gui/dependencys_controller.rb', line 239 def add_questions(questions) questions.each {|q| add_question(q)} return self end |