about summary refs log tree commit diff
path: root/app/models/export.rb
blob: 0eeac0dc0740c338d0f8e2df54d260b4a908fd67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require 'csv'

class Export
  attr_reader :account

  def initialize(account)
    @account = account
  end

  def to_blocked_accounts_csv
    to_csv account.blocking
  end

  def to_muted_accounts_csv
    to_csv account.muting
  end

  def to_following_accounts_csv
    to_csv account.following
  end

  def total_storage
    account.media_attachments.sum(:file_file_size)
  end

  def total_statuses
    account.statuses_count
  end

  def total_follows
    account.following_count
  end

  def total_followers
    account.followers_count
  end

  def total_blocks
    account.blocking.count
  end

  def total_mutes
    account.muting.count
  end

  private

  def to_csv(accounts)
    CSV.generate do |csv|
      accounts.each do |account|
        csv << [(account.local? ? account.local_username_and_domain : account.acct)]
      end
    end
  end
end