Class: Referral::PrintsResults

Inherits:
Object
  • Object
show all
Defined in:
lib/referral/prints_results.rb

Instance Method Summary collapse

Instance Method Details

#call(result, options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/referral/prints_results.rb', line 53

def call(result, options)
  if options[:print_headers]
    puts options[:columns].join(options[:delimiter])
  end

  result.tokens.each do |token|
    cells = options[:columns].map { |column_name|
      if (column = COLUMN_FUNCTIONS[column_name.to_sym])
        column.call(token)
      else
        raise Referral::Error.new("Column '#{column_name}' not found in Referral::COLUMN_FUNCTIONS")
      end
    }
    puts cells.join(options[:delimiter])
  end
end