export.rb 886 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # frozen_string_literal: true
  2. require 'csv'
  3. class Export
  4. attr_reader :account
  5. def initialize(account)
  6. @account = account
  7. end
  8. def to_blocked_accounts_csv
  9. to_csv account.blocking
  10. end
  11. def to_muted_accounts_csv
  12. to_csv account.muting
  13. end
  14. def to_following_accounts_csv
  15. to_csv account.following
  16. end
  17. def total_storage
  18. account.media_attachments.sum(:file_file_size)
  19. end
  20. def total_statuses
  21. account.statuses_count
  22. end
  23. def total_follows
  24. account.following_count
  25. end
  26. def total_followers
  27. account.followers_count
  28. end
  29. def total_blocks
  30. account.blocking.count
  31. end
  32. def total_mutes
  33. account.muting.count
  34. end
  35. private
  36. def to_csv(accounts)
  37. CSV.generate do |csv|
  38. accounts.each do |account|
  39. csv << [(account.local? ? account.local_username_and_domain : account.acct)]
  40. end
  41. end
  42. end
  43. end