Sha256: 7bf9696127d2d03b22c0315e1857206a2888189de33494ef4beb9b01f531ca51
Contents?: true
Size: 1.28 KB
Versions: 20
Compression:
Stored size: 1.28 KB
Contents
# { # "id": "intake_questionnaire", # "display_name": "Intake Questionnaire at Baseline Visit", # "code_book": "Baseline-Visit-Intake-Questionnaire.pdf" # } require 'json' module Spout module Models class Form attr_accessor :id, :display_name, :code_book attr_accessor :errors def initialize(file_name, dictionary_root) @errors = [] @id = file_name.to_s.gsub(/^(.*)\/|\.json$/, '').downcase @folder = file_name.to_s.gsub(/^#{dictionary_root}\/forms\/|#{@id}\.json$/, '') json = begin JSON.parse(File.read(file_name)) rescue => e form_name = file_name.to_s.gsub(/^(.*)\/|\.json$/, '').downcase @errors << "Error Parsing #{form_name}.json: #{e.message}" nil end if json and json.kind_of? Hash %w( display_name code_book ).each do |method| instance_variable_set("@#{method}", json[method]) end @errors << "'id': #{json['id'].inspect} does not match filename #{@id.inspect}" if @id != json['id'] elsif json @errors << "Form must be a valid hash in the following format: {\n\"id\": \"FORM_ID\",\n \"display_name\": \"FORM DISPLAY NAME\",\n \"code_book\": \"FORMPDF.pdf\"\n}" end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems