Class: LocationReport::LocationReportForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::AttributeMethods, ActiveModel::Model
Defined in:
app/models/location_report/location_report_form.rb

Overview

This form object class handles the user interaction for creating new Location Reports. It sensibility checks the user-entered list of barcode sequences or selection parameters before creating the Location Report model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#barcodesObject



60
61
62
# File 'app/models/location_report/location_report_form.rb', line 60

def barcodes
  @barcodes ||= barcodes_text&.squish&.split(/[\s,]+/) || []
end

#barcodes_textObject

Returns the value of attribute barcodes_text.



15
16
17
# File 'app/models/location_report/location_report_form.rb', line 15

def barcodes_text
  @barcodes_text
end

#end_dateObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def end_date
  @end_date
end

#faculty_sponsor_idsObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def faculty_sponsor_ids
  @faculty_sponsor_ids
end

#location_barcodeObject

Returns the value of attribute location_barcode.



16
17
18
# File 'app/models/location_report/location_report_form.rb', line 16

def location_barcode
  @location_barcode
end

#location_reportObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/location_report/location_report_form.rb', line 34

def location_report
  @location_report ||
    @location_report =
      LocationReport.new(
        user: user,
        name: name,
        report_type: report_type,
        location_barcode: location_barcode,
        faculty_sponsor_ids: faculty_sponsor_ids,
        study_id: study_id,
        start_date: start_date&.to_datetime,
        end_date: end_date&.to_datetime,
        plate_purpose_ids: plate_purpose_ids,
        barcodes: barcodes
      )
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'app/models/location_report/location_report_form.rb', line 16

def name
  @name
end

#plate_purpose_idsObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def plate_purpose_ids
  @plate_purpose_ids
end

#report_typeObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def report_type
  @report_type
end

#start_dateObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def start_date
  @start_date
end

#study_idObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def study_id
  @study_id
end

#userObject

Attributes



13
14
15
# File 'app/models/location_report/location_report_form.rb', line 13

def user
  @user
end

Class Method Details

.model_nameObject

form builder methods (e.g. form_to) need the Active Model name to be set



56
57
58
# File 'app/models/location_report/location_report_form.rb', line 56

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

Instance Method Details

#saveObject



51
52
53
# File 'app/models/location_report/location_report_form.rb', line 51

def save
  location_report.save if valid?
end