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


63
64
65
# File 'app/models/location_report/location_report_form.rb', line 63

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

#barcodes_textObject

Returns the value of attribute barcodes_text


22
23
24
# File 'app/models/location_report/location_report_form.rb', line 22

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

Attributes


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

def location_barcode
  @location_barcode
end

#location_reportObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/location_report/location_report_form.rb', line 39

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


22
23
24
# File 'app/models/location_report/location_report_form.rb', line 22

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


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

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

Instance Method Details

#saveObject


54
55
56
# File 'app/models/location_report/location_report_form.rb', line 54

def save
  location_report.save if valid?
end