Class: StudyEngine::ExistingAssessmentsForm

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Validations
Defined in:
app/models/study_engine/existing_assessments_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ExistingAssessmentsForm

Returns a new instance of ExistingAssessmentsForm.



17
18
19
20
21
22
23
# File 'app/models/study_engine/existing_assessments_form.rb', line 17

def initialize attributes = {}
  self.study_id = StudyID.new
  self.event_datetimes ||= []
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#event_datetimesObject

Returns the value of attribute event_datetimes.



36
37
38
# File 'app/models/study_engine/existing_assessments_form.rb', line 36

def event_datetimes
  @event_datetimes
end

#method_appliedObject

Returns the value of attribute method_applied.



36
37
38
# File 'app/models/study_engine/existing_assessments_form.rb', line 36

def method_applied
  @method_applied
end

#study_idObject

Returns the value of attribute study_id.



36
37
38
# File 'app/models/study_engine/existing_assessments_form.rb', line 36

def study_id
  @study_id
end

Class Method Details

.model_nameObject



9
10
11
# File 'app/models/study_engine/existing_assessments_form.rb', line 9

def self.model_name
  ActiveModel::Name.new(Assessment)
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/study_engine/existing_assessments_form.rb', line 32

def persisted?
  false
end

#saveObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/study_engine/existing_assessments_form.rb', line 49

def save
  if valid?
    base = Assessment.by_study_id(study_id)
    event_datetimes.each.with_index do |datetime, index|
      next if datetime.blank?
      event = StudyEngine.events[index]
      assessment = base.by_event(event).create!(created_at: datetime, assessment_updated_at: datetime, method_applied: method_applied)
      assessment.update_column :group_index, nil
    end
    true
  end
end

#study_optionsObject



45
46
47
# File 'app/models/study_engine/existing_assessments_form.rb', line 45

def study_options
  StudyID::Bank.studies
end

#to_keyObject



29
30
# File 'app/models/study_engine/existing_assessments_form.rb', line 29

def to_key
end

#to_modelObject



25
26
27
# File 'app/models/study_engine/existing_assessments_form.rb', line 25

def to_model
  self
end