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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qc_report, queue_count = 0) ⇒ QcReportPresenter


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

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


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

def qc_report
  @qc_report
end

#queue_countObject (readonly)

Returns the value of attribute queue_count


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

def queue_count
  @queue_count
end

Instance Method Details

#created_dateObject


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

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

#criteria_versionObject


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

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

#each_headerObject


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

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

#filenameObject


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

def filename
  "#{report_identifier}.csv"
end

#new_or_allObject


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

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

#product_nameObject


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

def product_name
  qc_report.product.name
end

#stateObject


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

def state
  qc_report.state.humanize
end

#state_descriptionObject


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

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

#study_abbreviationObject


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

def study_abbreviation
  qc_report.study.abbreviation
end

#study_nameObject


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

def study_name
  qc_report.study.name
end

#to_csv(io) ⇒ Object


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

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