Skip to content

Commit 15f5b96

Browse files
committed
Extract methods for hiding answers
* Reveals amount of non-instance state * Staging for decorator behavior
1 parent 6ef2410 commit 15f5b96

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

example_app/app/models/survey.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ class Survey < ActiveRecord::Base
1111

1212
def summaries_using(summarizer, options = {})
1313
questions.map do |question|
14-
if !options[:answered_by] || question.answered_by?(options[:answered_by])
15-
question.summary_using(summarizer)
16-
else
17-
Summary.new(question.title, NO_ANSWER)
18-
end
14+
summary_or_hidden_answer(summarizer, question, options[:answered_by])
1915
end
2016
end
17+
18+
private
19+
20+
def summary_or_hidden_answer(summarizer, question, answered_by)
21+
if hide_unanswered_question?(question, answered_by)
22+
hide_answer_to_question(question)
23+
else
24+
question.summary_using(summarizer)
25+
end
26+
end
27+
28+
def hide_unanswered_question?(question, answered_by)
29+
answered_by && !question.answered_by?(answered_by)
30+
end
31+
32+
def hide_answer_to_question(question)
33+
Summary.new(question.title, NO_ANSWER)
34+
end
2135
end

0 commit comments

Comments
 (0)