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



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

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[:lookup] ||= []
    context[:lookup] << [context[:question].reference_identifier, nil, context[:question]]
  end
  Surveyor::RedcapParser.rake_trace "question_#{context[:question].reference_identifier} "
end

#display_type_from_field_type(ft) ⇒ Object



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

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

#pick_from_field_type(ft) ⇒ Object



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

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