Class: REDCap::Form
- Inherits:
-
Object
- Object
- REDCap::Form
- Defined in:
- lib/red_cap/form.rb,
lib/red_cap/form/fields.rb
Defined Under Namespace
Classes: Checkboxes, CheckboxesWithCheckboxesOrOther, CheckboxesWithOther, CheckboxesWithRadioButtonsOrOther, Descriptive, Dropdown, Field, File, Notes, RadioButtons, Sql, Text, Yesno
Constant Summary collapse
- Radio =
default “radio” implementation
RadioButtons
- Checkbox =
default “checkbox” implementation
CheckboxesWithOther
Instance Attribute Summary collapse
-
#data_dictionary ⇒ Object
Returns the value of attribute data_dictionary.
-
#responses ⇒ Object
Returns the value of attribute responses.
Instance Method Summary collapse
- #fields ⇒ Object
- #find_field(key, field_class, options) ⇒ Object
-
#initialize(data_dictionary) ⇒ Form
constructor
A new instance of Form.
-
#method_missing(method, *args, **kwargs, &block) ⇒ Object
field accessors.
Constructor Details
#initialize(data_dictionary) ⇒ Form
Returns a new instance of Form.
6 7 8 |
# File 'lib/red_cap/form.rb', line 6 def initialize data_dictionary @data_dictionary = data_dictionary end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
field accessors
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/red_cap/form.rb', line 13 def method_missing method, *args, **kwargs, &block key = method.to_s = kwargs.dup field_class = .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, ) field.value(responses) else super end end |
Instance Attribute Details
#data_dictionary ⇒ Object
Returns the value of attribute data_dictionary.
10 11 12 |
# File 'lib/red_cap/form.rb', line 10 def data_dictionary @data_dictionary end |
#responses ⇒ Object
Returns the value of attribute responses.
10 11 12 |
# File 'lib/red_cap/form.rb', line 10 def responses @responses end |
Instance Method Details
#fields ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/red_cap/form.rb', line 27 def find_field key, field_class, field = fields.find { |field| field.field_name == key } field = field_class.new(field.attributes) if field_class field. = field end |