Skip to content

Commit

Permalink
Extract methods for hiding answers
Browse files Browse the repository at this point in the history
* Reveals amount of non-instance state
* Staging for decorator behavior
  • Loading branch information
jferris committed Feb 22, 2013
1 parent 6ef2410 commit 15f5b96
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions example_app/app/models/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.