@ -32,7 +32,7 @@ class SurveyItemValues
# We don't ensure that ids in the form of s-tint-q1 have a matching pair because not all questions have variants
# We don't ensure that ids in the form of s-tint-q1 have a matching pair because not all questions have variants
def include_all_headers ( headers : )
def include_all_headers ( headers : )
alternates = headers . filter ( & :present? )
alternates = headers . filter ( & :present? )
. filter { | header | header . end_with? " -1 " }
. filter { | header | header . match?( / ^[st]- \ w*- \ w*-1$ /i ) }
alternates . each do | header |
alternates . each do | header |
main = header . sub ( / -1 \ z / , " " )
main = header . sub ( / -1 \ z / , " " )
headers . push ( main ) unless headers . include? ( main )
headers . push ( main ) unless headers . include? ( main )
@ -192,11 +192,14 @@ class SurveyItemValues
output
output
end
end
def to_a
def sanitized_headers
headers . select ( & :present? )
@sanitized_headers || = headers . select ( & :present? )
. reject { | key , _value | key . start_with? " Q " }
. reject { | key , _value | key . start_with? " Q " }
. reject { | key , _value | key . end_with? " -1 " }
. reject { | key , _value | key . match? ( / ^[st]- \ w*- \ w*-1$ /i ) }
. map { | header | row [ header ] }
end
def to_a
sanitized_headers . map { | header | row [ header ] }
end
end
def duration
def duration
@ -216,12 +219,11 @@ class SurveyItemValues
end
end
def survey_type
def survey_type
survey_item_ids = headers
@survey_type || = SurveyItem . survey_type ( survey_item_ids : )
. filter ( & :present? )
end
. reject { | header | header . end_with? ( " -1 " ) }
. filter { | header | header . start_with? ( " t- " , " s- " ) }
SurveyItem . survey_type ( survey_item_ids : )
def survey_item_ids
@survey_item_ids || = sanitized_headers . filter { | header | header . start_with? ( " t- " , " s- " ) }
end
end
def valid_duration?
def valid_duration?
@ -236,10 +238,7 @@ class SurveyItemValues
end
end
def progress
def progress
headers . filter ( & :present? )
survey_item_ids . reject { | header | row [ header ] . nil? } . count
. reject { | header | header . end_with? ( " -1 " ) }
. filter { | header | header . start_with? ( " t- " , " s- " ) }
. reject { | header | row [ header ] . nil? } . count
end
end
def valid_progress?
def valid_progress?