Module: Surveyor::ActsAsResponse

Defined in:
lib/surveyor/acts_as_response.rb

Instance Method Summary collapse

Instance Method Details

#as(type_symbol) ⇒ Object

Returns the response as a particular response_class type



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/surveyor/acts_as_response.rb', line 4

def as(type_symbol)
  return case type_symbol.to_sym
  when :string, :text, :integer, :float, :datetime
    self.send("#{type_symbol}_value".to_sym)
  when :date
    self.datetime_value.nil? ? nil : self.datetime_value.to_date
  when :time
    self.datetime_value.nil? ? nil : self.datetime_value.to_time
  else # :answer_id
    self.answer_id
  end
end