This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
/
profile_page_presenter.rb
103 lines (82 loc) · 1.85 KB
/
profile_page_presenter.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true
class ProfilePagePresenter
attr_reader :user
def initialize(user)
@user = user
end
def display_pre_launch?
Hacktoberfest.pre_launch?
end
def display_post_launch?
Hacktoberfest.ended?
end
def display_coupon?
@user.won_shirt? || @user.won_sticker?
end
def display_sticker_gift?
@user.gifted_sticker?
end
def display_waiting_for_prize?
@user.completed?
end
def display_thank_you?
@user.incompleted?
end
def display_waiting_thank_you?
@user.waiting? && Hacktoberfest.ended?
end
def display_no_contributions?
@user.pull_requests.empty?
end
def display_timeline?
@user.pull_requests.any?
end
def scoring_pull_requests
# If the user has won, show their winning PRs
return persisted_winning_pull_requests if @user.receipt.present?
# Show all the PRs until we reach four winning/waiting
counter = 0
@user.pull_requests.take_while do |pr|
counter += 1 if pr.eligible? || pr.waiting?
counter <= 4
end
end
def persisted_winning_pull_requests
@user.receipt.map do |pr|
PullRequest.from_github_pull_request(
GithubPullRequest.new(Hashie::Mash.new(pr))
)
end
end
def non_scoring_pull_requests
# Show all the PRs not in the scoring section
scoring = scoring_pull_requests.map(&:github_id)
@user.pull_requests.reject { |pr| scoring.include?(pr.github_id) }
end
def score
if @user.completed_or_won?
4
else
@user.score || 0
end
end
def bonus_score
@user.bonus_score || 0
end
def name
@user.name
end
def show_timer?
@user.waiting?
end
def show_congratulations?
@user.completed_or_won?
end
def code
if (coupon = @user.shirt_coupon)
coupon.code
elsif (coupon = @user.sticker_coupon)
coupon.code
end
end
end