class Roqua::CsvExport::Models::Response

Public Instance Methods

flag(key) click to toggle source

@param key [String] prepended with questionnaire_key @return [String]

# File lib/roqua/csv_export/models/response.rb, line 50
def flag(key)
  response_flags.find { |response_flag| response_flag.key == key }.value
end
score(key, sub_key) click to toggle source

Retrieve a score value. main value for a score will usually have sub_key “value”. @param key [String] e.g. “tot” @param sub_key [String] e.g. “value” or “interpretation” @return [String]

# File lib/roqua/csv_export/models/response.rb, line 44
def score(key, sub_key)
  score_hash.dig(key, sub_key)
end
score_hash() click to toggle source

List of calculated scores. @return [Hash{String=>Hash{String}}] !{'tot' => {'value' => '15', …}, …}

# File lib/roqua/csv_export/models/response.rb, line 27
def score_hash
  @response_score_hash ||= response_scores.each_with_object({}) do |response_score, hash|
    (hash[response_score.score_key] ||= {})[response_score.score_subkey] = response_score.data
  end
end
textvar(key) click to toggle source

@param key [String] prepended with questionnaire_key. @return [String]

# File lib/roqua/csv_export/models/response.rb, line 56
def textvar(key)
  response_textvars.find { |response_textvar| response_textvar.key == key }.value
end
variable(key) click to toggle source

Get answer belonging to given key. @param key [String] e.g. “v_1” @return [String] The value for specified question_key

# File lib/roqua/csv_export/models/response.rb, line 36
def variable(key)
  variable_hash[key]
end
variable_hash() click to toggle source

List of answers to questions. @return [Hash{String=>String}] !{'v_1' => '3', …}

# File lib/roqua/csv_export/models/response.rb, line 19
def variable_hash
  @variable_hash ||= response_values.each_with_object({}) do |response_value, hash|
    hash[response_value.question_key] = response_value.data
  end
end