Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. CSV.generate(options) do |csv|
  2. columns = %w(name, email_address)
  3. url = "@example.com"
  4. all.each do |location|
  5. csv << location.attributes.values_at(*columns) + [url]
  6. end
  7. end
  8.  
  9. Joe, user1, @example.com
  10. Bob, user2, @example.com
  11.  
  12. Joe, user1@example.com
  13. Bob, user2@example.com
  14.  
  15. CSV.generate(options) do |csv|
  16. domain = "example.com"
  17.  
  18. all.each do |location|
  19. csv << [location.name, "#{location.email_address}@#{domain}"]
  20. end
  21. end
  22.  
  23. class Location << ActiveRecord::Base
  24. def full_email_address
  25. return "" if self.email_address.blank?
  26.  
  27. domain = "example.com" # or save this as a constant in the class
  28. "#{self.email_address}@#{domain}"
  29. end
  30. end
  31.  
  32. CSV.generate(options) do |csv|
  33. columns = %w{name full_email_address} # add other methods or attributes here
  34.  
  35. all.each do |location|
  36. csv << columns.map{ |moa| location.public_send(moa) }
  37. end
  38. end
  39.  
  40. CSV.generate(options) do |csv|
  41. columns = %w(name, email_address)
  42. url = "@example.com"
  43. all.each do |location|
  44. row = location.attributes.values_at(*columns)
  45. row[-1] = row[-1] + url
  46. csv << row
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement