Last active
December 17, 2015 15:29
-
-
Save tpendragon/5631691 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
class BooleanSurvey < Survey | |
def self.translate_answer(answer) | |
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(answer) | |
end | |
end |
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
class Survey < ActiveRecord::Base | |
attr_accessible :end_date, :start_date, :title, :question | |
validates :title, :presence => true | |
# Returns a string interpretation of the answer given. | |
# @note This should be overriden by specific survey types. | |
def self.translate_answer(answer) | |
answer.to_s | |
end | |
end |
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
subject.class | |
=> Survey::BooleanSurvey(id: integer, title: string, start_date: date, end_date: date, created_at: datetime, updated_at: datetime, question: string, type: string) | |
subject.class.translate_answer('test') | |
=> "test" | |
Survey::BooleanSurvey.translate_answer('test') | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment