class SiteHealth::IssuesReport
Public Class Methods
new(issues) { |self| ... }
click to toggle source
# File lib/site_health/issues_report.rb, line 9 def initialize(issues) @issues = issues @fields = Issue.fields @select_block = proc { true } yield(self) if block_given? end
Public Instance Methods
fields=(fields)
click to toggle source
# File lib/site_health/issues_report.rb, line 16 def fields=(fields) @fields = fields.map(&:to_sym) end
select(&block)
click to toggle source
# File lib/site_health/issues_report.rb, line 20 def select(&block) @select_block = block end
to_a()
click to toggle source
# File lib/site_health/issues_report.rb, line 24 def to_a issues = [] each { |data| issues << data } issues end
to_csv()
click to toggle source
# File lib/site_health/issues_report.rb, line 30 def to_csv CSV.generate do |csv| csv << @fields each { |data| csv << data.values_at(*@fields) } end end
to_json()
click to toggle source
# File lib/site_health/issues_report.rb, line 37 def to_json JSON.dump(to_a) end
Private Instance Methods
each() { |hash| ... }
click to toggle source
# File lib/site_health/issues_report.rb, line 43 def each @issues.each do |issue| next unless @select_block.call(issue) hash = issue.to_h.select { |k| @fields.include?(k) } yield(hash) end end