Permalink
Browse files

Extract methods for hiding answers

* Reveals amount of non-instance state
* Staging for decorator behavior
  • Loading branch information...
jferris committed Feb 20, 2013
1 parent 6ef2410 commit 15f5b96ed2f7f63825bde32e7ed3e52ce34a4ef5
Showing with 19 additions and 5 deletions.
  1. +19 −5 example_app/app/models/survey.rb
@@ -11,11 +11,25 @@ class Survey < ActiveRecord::Base

def summaries_using(summarizer, options = {})
questions.map do |question|
if !options[:answered_by] || question.answered_by?(options[:answered_by])
question.summary_using(summarizer)
else
Summary.new(question.title, NO_ANSWER)
end
summary_or_hidden_answer(summarizer, question, options[:answered_by])
end
end

private

def summary_or_hidden_answer(summarizer, question, answered_by)
if hide_unanswered_question?(question, answered_by)
hide_answer_to_question(question)
else
question.summary_using(summarizer)
end
end

def hide_unanswered_question?(question, answered_by)
answered_by && !question.answered_by?(answered_by)
end

def hide_answer_to_question(question)
Summary.new(question.title, NO_ANSWER)
end
end

0 comments on commit 15f5b96

Please sign in to comment.