Sha256: 9e224710ee168620aa4d164e2bb0146e81c295843c2a5b8466f5d8437cb9cad7
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 KB
Contents
module SurveyGizmo::API class Response include SurveyGizmo::Resource # Filters NO_TEST_DATA = { field: 'istestdata', operator: '<>', value: 1 } ONLY_COMPLETED = { field: 'status', operator: '=', value: 'Complete' } def self.submitted_since_filter(time) { field: 'datesubmitted', operator: '>=', value: time.in_time_zone('Eastern Time (US & Canada)').strftime('%Y-%m-%d %H:%M:%S') } end attribute :id, Integer attribute :survey_id, Integer attribute :contact_id, Integer attribute :data, String attribute :status, String attribute :is_test_data, Boolean attribute :sResponseComment, String attribute :variable, Hash # READ-ONLY attribute :meta, Hash # READ-ONLY attribute :shown, Hash # READ-ONLY attribute :url, Hash # READ-ONLY attribute :answers, Hash # READ-ONLY attribute :datesubmitted, DateTime alias_attribute :submitted_at, :datesubmitted @route = '/survey/:survey_id/surveyresponse' def survey @survey ||= Survey.first(id: survey_id) end def parsed_answers answers.select do |k,v| next false unless v.is_a?(FalseClass) || v.present? # Strip out "Other" answers that don't actually have the "other" text (they come back as two responses - one # for the "Other" option_id, and then a whole separate response for the text given as an "Other" response. if k =~ /\[question\((\d+)\),\s*option\((\d+)\)\]/ !answers.keys.any? { |key| key =~ /\[question\((#{$1})\),\s*option\("(#{$2})-other"\)\]/ } else true end end.map { |k,v| Answer.new(children_params.merge(key: k, value: v, answer_text: v, submitted_at: submitted_at)) } end end end
Version data entries
4 entries across 4 versions & 1 rubygems