Module: Census::User::InstanceMethods

Defined in:
lib/census/user.rb

Instance Method Summary collapse

Instance Method Details

#all_answers_for(question) ⇒ Object

Returns an array of this user’s answers for the given question. The returned array will be empty if the user has not answered this question.



82
83
84
# File 'lib/census/user.rb', line 82

def all_answers_for(question)
  answers.select {|a| a.question == question}
end

#answer_for_choice(choice) ⇒ Object

Returns this user’s answer for a specific choice under a multiple-choice question, or a new empty answer if the user did not select the given choice.



90
91
92
# File 'lib/census/user.rb', line 90

def answer_for_choice(choice)
  answers.select {|a| a.question == choice.question && a.data == choice.value}.first || answers.build(:question => choice.question, :data => '')
end

#census_dataObject

Returns a Census::UserData object that can be used to retrieve this user’s answers.



98
99
100
# File 'lib/census/user.rb', line 98

def census_data
  @census_data ||= Census::UserData.new(self)
end

#first_answer_for(question) ⇒ Object

Returns this user’s first answer for the given question, or a new empty answer if the user has not answered the question.



74
75
76
# File 'lib/census/user.rb', line 74

def first_answer_for(question)
  answers.select {|a| a.question == question}.first || answers.build(:question => question, :data => '')
end