Sha256: 1139114f03b0291c50d6da4c51b5763eecc14d9d3bb60c3f5e969e8e4bd1bcea
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
# frozen_string_literal: true # { # "id": "intake_questionnaire", # "display_name": "Intake Questionnaire at Baseline Visit", # "code_book": "Baseline-Visit-Intake-Questionnaire.pdf" # } require "spout/models/record" module Spout module Models class Form < Spout::Models::Record attr_accessor :id, :folder, :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, encoding: "utf-8")) rescue => e form_name = file_name.to_s.gsub(/^(.*)\/|\.json$/, "").downcase @errors << "Error Parsing #{form_name}.json: #{e.message}" nil end if json.is_a? 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 def deploy_params { name: id, folder: folder.to_s.gsub(%r{/$}, ""), display_name: display_name, code_book: code_book, spout_version: Spout::VERSION::STRING } end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
spout-1.0.0 | lib/spout/models/form.rb |
spout-1.0.0.beta3 | lib/spout/models/form.rb |
spout-1.0.0.beta2 | lib/spout/models/form.rb |