Sha256: 313dfe8614267f3b3cede59caa88355579e39609cf16d4aad1e4cc11663ff1e2
Contents?: true
Size: 1.31 KB
Versions: 7
Compression:
Stored size: 1.31 KB
Contents
require "red_cap/form/fields" require "active_support/core_ext/string/inflections" module REDCap class Form def initialize data_dictionary, responses @data_dictionary = data_dictionary @responses = responses end attr_reader :data_dictionary, :responses # field accessors def method_missing method, *args, **kwargs, &block key = method.to_s options = kwargs.dup field_class = options.delete(:as) if field_class.is_a?(Symbol) field_class = lookup_field_class(field_class.to_s) end if field = find_field(key, field_class, options) field.value else super end end def find_field key, field_class, options field = fields.find { |field| field.field_name == key } field = field_class.new(self, field.attributes, responses) if field_class field.options = options field end def fields @fields ||= data_dictionary.map do |attributes| klass = lookup_field_class(attributes["field_type"]) klass.new(self, attributes, responses) end end private def lookup_field_class field_type self.class.const_get field_type.camelize, false rescue NameError puts "Unimplemented field type: #{field_type}. Falling back to Text." Text end end end
Version data entries
7 entries across 7 versions & 1 rubygems