def parse(str, filename)
      csvlib = Surveyor::Common.csv_impl
      begin
        csvlib.parse(str, :headers => :first_row, :return_headers => true, :header_converters => :symbol) do |r|
          if r.header_row? # header row
            return Surveyor::RedcapParser.rake_trace "Missing headers: #{missing_columns(r.headers).inspect}\n\n" unless missing_columns(r.headers).blank?
            context[:survey] = Survey.new(:title => filename)
            Surveyor::RedcapParser.rake_trace "survey_#{context[:survey].access_code} "
          else # non-header rows
            SurveySection.new.extend(SurveyorRedcapParserSurveySectionMethods).build_or_set(context, r)
            Question.new.extend(SurveyorRedcapParserQuestionMethods).build_and_set(context, r)
            Answer.new.extend(SurveyorRedcapParserAnswerMethods).build_and_set(context, r)
            Validation.new.extend(SurveyorRedcapParserValidationMethods).build_and_set(context, r)
            Dependency.new.extend(SurveyorRedcapParserDependencyMethods).build_and_set(context, r)
          end
        end
        resolve_references
        Surveyor::RedcapParser.rake_trace context[:survey].save ? "saved. " : " not saved! #{context[:survey].errors.full_messages.join(", ")} "
        # Surveyor::RedcapParser.rake_trace context[:survey].sections.map(&:questions).flatten.map(&:answers).flatten.map{|x| x.errors.each_full{|y| y}.join}.join
      rescue csvlib::MalformedCSVError
        raise Surveyor::RedcapParserError, "Oops. Not a valid CSV file."
      # ensure
      end
      return context[:survey]
    end
def parse(str, filename)
      csvlib = Surveyor::Common.csv_impl
      begin
        csvlib.parse(str, :headers => :first_row, :return_headers => true, :header_converters => :symbol) do |r|
          if r.header_row? # header row
            return Surveyor::RedcapParser.rake_trace "Missing headers: #{missing_columns(r.headers).inspect}\n\n" unless missing_columns(r.headers).blank?
            context[:survey] = Survey.new(:title => filename)
            Surveyor::RedcapParser.rake_trace "survey_#{context[:survey].access_code} "
          else # non-header rows
            SurveySection.new.extend(SurveyorRedcapParserSurveySectionMethods).build_or_set(context, r)
            Question.new.extend(SurveyorRedcapParserQuestionMethods).build_and_set(context, r)
            Answer.new.extend(SurveyorRedcapParserAnswerMethods).build_and_set(context, r)
            Validation.new.extend(SurveyorRedcapParserValidationMethods).build_and_set(context, r)
            Dependency.new.extend(SurveyorRedcapParserDependencyMethods).build_and_set(context, r)
          end
        end
        resolve_references
        Surveyor::RedcapParser.rake_trace context[:survey].save ? "saved. " : " not saved! #{context[:survey].errors.full_messages.join(", ")} "
        # Surveyor::RedcapParser.rake_trace context[:survey].sections.map(&:questions).flatten.map(&:answers).flatten.map{|x| x.errors.each_full{|y| y}.join}.join
      rescue csvlib::MalformedCSVError
        raise Surveyor::RedcapParserError, "Oops. Not a valid CSV file."
      # ensure
      end
      return context[:survey]
    end
Instance methods