Module: IDeleteMyTweets::Presenter

Included in:
Api, CommandConvert
Defined in:
lib/i_delete_my_tweets/presenter.rb

Constant Summary collapse

COLORS =
[
  :red,
  :green,
  :yellow,
  :blue,
  :magenta,
  :cyan
].freeze
TABLE_STYLE =
{border: Terminal::Table::UnicodeRoundBorder.new}.freeze

Instance Method Summary collapse

Instance Method Details

#summary(delete_count, skipped_count, not_found_count, dry_run) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/i_delete_my_tweets/presenter.rb', line 14

def summary(delete_count, skipped_count, not_found_count, dry_run)
  Terminal::Table.new do |table|
    table.title = "Summary"
    table.headings = ["Deleted", "Skipped", "Not Found", "Dry Run?"]
    table.rows = [[delete_count, skipped_count, not_found_count, dry_run.present?]]
    table.style = TABLE_STYLE
  end
end

#to_date(timestamp) ⇒ Object



53
54
55
# File 'lib/i_delete_my_tweets/presenter.rb', line 53

def to_date(timestamp)
  Date.parse timestamp
end

#to_human_time(time) ⇒ Object



57
58
59
# File 'lib/i_delete_my_tweets/presenter.rb', line 57

def to_human_time(time)
  time.strftime("%Y-%m-%d %H:%M")
end

#truncate(text) ⇒ Object



49
50
51
# File 'lib/i_delete_my_tweets/presenter.rb', line 49

def truncate(text)
  text.gsub(/^(.{40,}?).*$/m, '\1...')
end

#tweet_not_found(tweet_id, dry_run, verbose: true) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/i_delete_my_tweets/presenter.rb', line 36

def tweet_not_found(tweet_id, dry_run, verbose: true)
  if verbose
    Terminal::Table.new do |table|
      table.title = "💥 Tweet Not Found 💥"
      table.headings = ["ID", "Dry Run?"]
      table.rows = [[tweet_id, dry_run.present?]]
      table.style = TABLE_STYLE
    end
  else
    ".💥 "
  end
end

#tweet_presenter(tweet, dry_run, verbose: true) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/i_delete_my_tweets/presenter.rb', line 23

def tweet_presenter(tweet, dry_run, verbose: true)
  if verbose
    Terminal::Table.new do |table|
      table.title = "🐤 Deleted Tweet 🚽"
      table.headings = ["Text", "Date", "Faves", "RTs", "Dry Run?"]
      table.rows = [[truncate(tweet.text), to_human_time(tweet.created_at), tweet.favorite_count, tweet.retweet_count, dry_run.present?]]
      table.style = TABLE_STYLE
    end
  else
    ".🐤 "
  end
end