missinglink 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ab020970fa34b7686f693901d08b96088f9089
4
- data.tar.gz: f0a3ad6302bce18822d17faeddfee59bf775325d
3
+ metadata.gz: 1e4831b34c8d0eda8eb16a551b660387e36a6a46
4
+ data.tar.gz: fcc9a4b5fd84fd88979877abe8c7f3abe265e836
5
5
  SHA512:
6
- metadata.gz: 557e5969361e996f5b6f3206c2296c8904c51c1597f5759ac2dbd4350a2aeffe28c480f3ec33bd528e0203f1f47416191d95cd5d1426318a5826421c9e3ddc78
7
- data.tar.gz: 3aa659a7708656e19dfd80c76864c83816905e80c629a7a25a8606606c10a4e05ef3e93824ac73dc38079859a6b427efa2aebd242f4a38a1c792cf2102eda085
6
+ metadata.gz: 48717c4b4be1426742ce7e6b18ba29c576ea5cecc19d97fcdfdeb5ee8dd58dcf1c04cfffd79edb5221dd81eec9df97b4bd93c7b7cb33c3b2ed09b5ca44b0ace2
7
+ data.tar.gz: 461808ece66053ba3d1d614d3c435e3354da7ac3e1bcd3919098409483c99cb8dd53072e109ef598277e267c9bdffb64e3fec7b390380e82ae6e96eadc1810f4
@@ -18,6 +18,12 @@ module Missinglink
18
18
  answer.survey_question = question
19
19
  answer.save
20
20
 
21
+ if hash['items'] then
22
+ hash['items'].each do |sub_item|
23
+ SurveyAnswer.parse(question, sub_item)
24
+ end
25
+ end
26
+
21
27
  return answer
22
28
  end
23
29
 
@@ -6,6 +6,7 @@ module Missinglink
6
6
  has_many :survey_pages, through: :survey_page_questions
7
7
  has_many :survey_answers
8
8
  has_many :survey_responses
9
+ has_many :survey_response_answers, through: :survey_responses
9
10
 
10
11
  def self.parse(page, hash)
11
12
  question = SurveyQuestion.first_or_create_by_sm_id(hash['question_id'])
@@ -31,5 +32,66 @@ module Missinglink
31
32
  return SurveyQuestion.create(sm_question_id: sm_id)
32
33
  end
33
34
  end
35
+
36
+ # for reference, when searching, listing all possible responses is
37
+ # logical, but it is impossible to track all survey response answers
38
+ # that match the desired answer. therefore, we only track one
39
+ # example, and later find all similar response answers based on the
40
+ # question strategy
41
+ def possible_responses(search_other = false)
42
+ {}.tap do |hash|
43
+ survey_response_answers.each do |sra|
44
+ sa_row = (sra.row_survey_answer_id ? SurveyAnswer.find(sra.row_survey_answer_id) : nil)
45
+ sa_col = (sra.col_survey_answer_id ? SurveyAnswer.find(sra.col_survey_answer_id) : nil)
46
+ sa_col_choice = (sra.col_choice_survey_answer_id ? SurveyAnswer.find(sra.col_choice_survey_answer_id) : nil)
47
+ other_text = ((!search_other || sra.text.nil?) ? nil : "Other: #{ sra.text }")
48
+
49
+ case answer_strategy
50
+ when "first_survey_response_answer_text"
51
+ hash[sra.text] = sra.id unless (sra.text.nil? || hash[sra.text])
52
+ when "answer_row_match_for_survey_response_answer_text"
53
+ hash[sa_row.text] = sra.id unless (sa_row.nil? || hash[sa_row.text])
54
+ hash[other_text] = sra.id unless (other_text.nil? || hash[other_text])
55
+ when "row_column_survey_response_answers_and_text"
56
+ main_text = "#{ sa_row.try(:text) }: #{ sa_col.try(:text) }"
57
+ hash[main_text] = sra.id unless (sa_row.nil? || sa_col.nil? || hash[main_text])
58
+ hash[other_text] = sra.id unless (other_text.nil? || hash[other_text])
59
+ when "row_column_and_choice_survey_response_answers_and_text"
60
+ main_text = "#{ sa_row.try(:text) }, #{ sa_col.try(:text) }: #{ sa_col_choice.try(:text) }"
61
+ hash[main_text] = sra.id unless (sa_row.nil? || sa_col.nil? || sa_col_choice.nil? || hash[main_text])
62
+ hash[other_text] = sra.id unless (other_text.nil? || hash[other_text])
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def similar_response_answers(response_answer, search_other = false)
69
+ if search_other || answer_strategy == "first_survey_response_answer_text"
70
+ return survey_response_answers.select { |sra| sra.text == response_answer.text }.sort
71
+ end
72
+
73
+ case answer_strategy
74
+ when "answer_row_match_for_survey_response_answer_text"
75
+ survey_response_answers.select do |sra|
76
+ sra.row_survey_answer_id == response_answer.row_survey_answer_id
77
+ end.sort
78
+ when "row_column_survey_response_answers_and_text"
79
+ survey_response_answers.select do |sra|
80
+ sra.row_survey_answer_id == response_answer.row_survey_answer_id &&
81
+ sra.col_survey_answer_id == response_answer.col_survey_answer_id
82
+ end.sort
83
+ when "row_column_and_choice_survey_response_answers_and_text"
84
+ survey_response_answers.select do |sra|
85
+ sra.row_survey_answer_id == response_answer.row_survey_answer_id &&
86
+ sra.col_survey_answer_id == response_answer.col_survey_answer_id &&
87
+ sra.col_choice_survey_answer_id == response_answer.col_choice_survey_answer_id
88
+ end.sort
89
+ end
90
+ end
91
+
92
+ private
93
+ def answer_strategy
94
+ Missinglink.answer_strategies[type_family][type_subtype]
95
+ end
34
96
  end
35
97
  end
@@ -1,3 +1,3 @@
1
1
  module Missinglink
2
- VERSION = "0.2"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/missinglink.rb CHANGED
@@ -30,4 +30,8 @@ module Missinglink
30
30
  def fetch_response_answers(survey, respondents)
31
31
  survey.load_response_details(respondents)
32
32
  end
33
+
34
+ def answer_strategies
35
+ @@answer_strategies ||= YAML.load_file("etc/question_types.yml")
36
+ end
33
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: missinglink
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Springer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails