Last active
August 18, 2017 18:04
-
-
Save smoyte/5e75cbb68231b0b24beac3ea6ff881db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.decorate_collection(collection) | |
collection.map { |q| self.class.new(q, loan) } | |
end | |
# Returns child questions that are applicable to the given loan. Sorts by requiredness, then position. | |
def children | |
@children ||= decorated_children.select(&:visible?).sort_by(&:reqpos) | |
end | |
def answered? | |
response_set && !response_set.tree_unanswered?(object) | |
end | |
private | |
def decorated_children | |
self.class.decorate_collection(object.children) | |
end | |
# Returns an array of the form [<required>, <position>] where required is 1 if question is required, | |
# 2 if not, and position is the questions position. Used for sorting. | |
def reqpos | |
@reqpos ||= [required? ? 1 : 2, position] | |
end | |
def visible? | |
status == 'active' || (status == 'inactive' && answered?) | |
end | |
def response_set | |
@response_set ||= loan.send(loan_question_set.kind) | |
end | |
def prep_questionnaire | |
@attrib = params[:filter] || "criteria" | |
@response_set ||= @loan.send(@attrib) || LoanResponseSet.new(kind: @attrib, loan: @loan) | |
root = @response_set.loan_question_set.root_group_preloaded | |
@top_level_questions = QuestionDecorator.new(root, @loan).children | |
@questions_json = @top_level_questions.map { |q| LoanQuestionSerializer.new(q) }.to_json | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment