Class: Dossier::Result::Formatted

Inherits:
Dossier::Result show all
Defined in:
lib/dossier/result.rb

Instance Attribute Summary

Attributes inherited from Dossier::Result

#adapter_results, #report

Instance Method Summary collapse

Methods inherited from Dossier::Result

#arrays, #body, #footers, #hashes, #initialize, #raw_headers, #row_hash, #rows

Constructor Details

This class inherits a constructor from Dossier::Result

Instance Method Details

#eachObject



58
59
60
# File 'lib/dossier/result.rb', line 58

def each
  adapter_results.rows.each { |row| yield format(row) }
end

#format(row) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dossier/result.rb', line 62

def format(row)
  unless row.kind_of?(Enumerable)
    raise ArgumentError.new("#{row.inspect} must be a kind of Enumerable") 
  end

  row.each_with_index.map do |value, i|
    column = raw_headers.at(i)
    method = "format_#{column}"

    if report.respond_to?(method)
      args = [method, value]
      # Provide the row as context if the formatter takes two arguments
      args << row_hash(row) if report.method(method).arity == 2
      report.public_send(*args)
    else
      report.format_column(column, value)
    end
  end
end

#headersObject



54
55
56
# File 'lib/dossier/result.rb', line 54

def headers
  @formatted_headers ||= raw_headers.map { |h| report.format_header(h) }
end