class REDCap::Form
Constants
- Checkbox
default “checkbox” implementation
- Radio
default “radio” implementation
Attributes
data_dictionary[RW]
responses[RW]
Public Class Methods
new(data_dictionary)
click to toggle source
# File lib/red_cap/form.rb, line 6 def initialize data_dictionary @data_dictionary = data_dictionary end
Public Instance Methods
fields()
click to toggle source
# File lib/red_cap/form.rb, line 34 def fields @fields ||= begin fs = data_dictionary.map do |attributes| klass = lookup_field_class(attributes["field_type"]) klass.new(attributes) end fs.each do |field| field.associated_fields = fs.select do |f| f.branching_logic =~ /^\[#{field.field_name}\(.+\)\]="1"$/ end end fs end end
find_field(key, field_class, options)
click to toggle source
# File lib/red_cap/form.rb, line 27 def find_field key, field_class, options field = fields.find { |field| field.field_name == key } field = field_class.new(field.attributes) if field_class field.options = options field end
method_missing(method, *args, **kwargs, &block)
click to toggle source
field accessors
Calls superclass method
# File lib/red_cap/form.rb, line 13 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(responses) else super end end
Private Instance Methods
lookup_field_class(field_type)
click to toggle source
# File lib/red_cap/form.rb, line 51 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