class Dossier::Result::Formatted

Public Instance Methods

each() { |format(row)| ... } click to toggle source
# File lib/dossier/result.rb, line 62
def each
  adapter_results.rows.each { |row| yield format(row) }
end
format(row) click to toggle source
# File lib/dossier/result.rb, line 66
def format(row)
  unless row.kind_of?(Enumerable)
    raise ArgumentError.new("#{row.inspect} must be a kind of Enumerable") 
  end
  
  displayable_columns(row).map { |value, i|
    column = raw_headers.at(i)
    apply_formatter(row, column, value)
  }
end
headers() click to toggle source
# File lib/dossier/result.rb, line 54
def headers
  @formatted_headers ||= raw_headers.select { |h|
    report.display_column?(h)
  }.map { |h|
    report.format_header(h)
  }
end

Private Instance Methods

apply_formatter(row, column, value) click to toggle source
# File lib/dossier/result.rb, line 86
def apply_formatter(row, column, value)
  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
displayable_columns(row) click to toggle source
# File lib/dossier/result.rb, line 79
def displayable_columns(row)
  row.each_with_index.select { |value, i|
    column = raw_headers.at(i)
    report.display_column?(column)
  }
end