Class: Presenters::QcReportPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/models/presenters/qc_report_presenter.rb

Constant Summary collapse

REPORT_IDENTITY =
'Sequencescape QC Report'
VERSION =
'1.0.0'
HEADER_FIELDS =
{
  'Study' => :study_name,
  'Product' => :product_name,
  'Criteria Version' => :criteria_version,
  'Report Identifier' => :report_identifier,
  'Generated on' => :created_date,
  'Contents' => :new_or_all
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qc_report, queue_count = 0) ⇒ QcReportPresenter

Returns a new instance of QcReportPresenter.



16
17
18
19
# File 'app/models/presenters/qc_report_presenter.rb', line 16

def initialize(qc_report, queue_count = 0)
  @qc_report = qc_report
  @queue_count = queue_count
end

Instance Attribute Details

#qc_reportObject (readonly)

Returns the value of attribute qc_report.



14
15
16
# File 'app/models/presenters/qc_report_presenter.rb', line 14

def qc_report
  @qc_report
end

#queue_countObject (readonly)

Returns the value of attribute queue_count.



14
15
16
# File 'app/models/presenters/qc_report_presenter.rb', line 14

def queue_count
  @queue_count
end

Instance Method Details

#created_dateObject



49
50
51
# File 'app/models/presenters/qc_report_presenter.rb', line 49

def created_date
  qc_report.created_at.to_fs(:rfc822)
end

#criteria_versionObject



25
26
27
# File 'app/models/presenters/qc_report_presenter.rb', line 25

def criteria_version
  "#{qc_report.product_criteria.stage}_#{qc_report.product_criteria.version}"
end

#each_headerObject



68
69
70
# File 'app/models/presenters/qc_report_presenter.rb', line 68

def each_header
  HEADER_FIELDS.each { |field, lookup| yield [field, send(lookup)] }
end

#filenameObject



21
22
23
# File 'app/models/presenters/qc_report_presenter.rb', line 21

def filename
  "#{report_identifier}.csv"
end

#new_or_allObject



45
46
47
# File 'app/models/presenters/qc_report_presenter.rb', line 45

def new_or_all
  qc_report.exclude_existing ? 'New samples' : 'All samples'
end

#product_nameObject



29
30
31
# File 'app/models/presenters/qc_report_presenter.rb', line 29

def product_name
  qc_report.product.name
end

#stateObject



41
42
43
# File 'app/models/presenters/qc_report_presenter.rb', line 41

def state
  qc_report.state.humanize
end

#state_descriptionObject



53
54
55
# File 'app/models/presenters/qc_report_presenter.rb', line 53

def state_description
  I18n.t(qc_report.state, scope: 'qc_reports.state_descriptions', default: :default, queue_count: queue_count)
end

#study_abbreviationObject



37
38
39
# File 'app/models/presenters/qc_report_presenter.rb', line 37

def study_abbreviation
  qc_report.study.abbreviation
end

#study_nameObject



33
34
35
# File 'app/models/presenters/qc_report_presenter.rb', line 33

def study_name
  qc_report.study.name
end

#to_csv(io) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/models/presenters/qc_report_presenter.rb', line 57

def to_csv(io)
  @csv = CSV.new(io)
  csv_headers
  @csv << [] # Pad with an empty line
  csv_field_headers
  csv_body
  @csv
end