Module: SurveyorRedcapParserQuestionMethods

Defined in:
lib/surveyor/redcap_parser.rb

Overview

Question model

Instance Method Summary collapse

Instance Method Details

#build_and_set(context, r) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/surveyor/redcap_parser.rb', line 104

def build_and_set(context, r)
  if !r[:section_header].blank?
    context[:survey_section].questions.build({:display_type => "label", :text => r[:section_header], :display_order => context[:survey_section].questions.size})
    Surveyor::RedcapParser.rake_trace "label_ "
  end
  self.attributes = ({
    :reference_identifier => r[:variable__field_name],
    :text => r[:field_label],
    :help_text => r[:field_note],
    :is_mandatory => (/^y/i.match r[:required_field]) ? true : false,
    :pick => pick_from_field_type(r[:field_type]),
    :display_type => display_type_from_field_type(r[:field_type]),
    :display_order => context[:survey_section].questions.size
  })
  context[:survey_section].questions << context[:question] = self
  unless context[:question].reference_identifier.blank?
    context[:question_references] ||= {}
    context[:question_references][context[:question].reference_identifier] = context[:question]
  end
  Surveyor::RedcapParser.rake_trace "question_#{context[:question].reference_identifier} "
end

#display_type_from_field_type(ft) ⇒ Object



128
129
130
# File 'lib/surveyor/redcap_parser.rb', line 128

def display_type_from_field_type(ft)
  {"text" => :string, "dropdown" => :dropdown, "notes" => :text}[ft]
end

#pick_from_field_type(ft) ⇒ Object



125
126
127
# File 'lib/surveyor/redcap_parser.rb', line 125

def pick_from_field_type(ft)
  {"checkbox" => :any, "radio" => :one}[ft] || :none
end