This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
auction_list_item.rb
127 lines (100 loc) · 2.22 KB
/
auction_list_item.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class AuctionListItem
attr_reader :auction, :current_user
def initialize(auction:, current_user:)
@auction = auction
@current_user = current_user
end
def label
status_presenter.label
end
def label_class
status_presenter.label_class
end
def title
auction.title
end
def id
auction.id
end
def html_summary
MarkdownRender.new(auction.summary).to_s
end
def capitalized_formatted_type
auction.type.dasherize.capitalize
end
def starting_price
Currency.new(auction.start_price).to_s
end
def eligibility_label
if for_small_business?
'Small-business only'
else
'SAM.gov only'
end
end
def skills
auction.sorted_skill_names.join(', ')
end
def github_repo
auction.github_repo
end
def project_label_partial
if auction.github_repo
'auctions/project_label'
else
'components/null'
end
end
def project_label
auction.github_repo.sub('https://github.com/', '')
end
def winning_bid_partial
if over? && !auction.bids.any?
'auctions/no_bids'
elsif over?
'auctions/over_winning_bid_details'
elsif auction.type == 'reverse' && available? && auction.bids.any?
'auctions/winning_bid_details'
else # sealed or reverse with no bids or future
'auctions/starting_price'
end
end
def relative_time
status_presenter.relative_time
end
def highlighted_bid_amount_as_currency
Currency.new(highlighted_bid.amount).to_s
end
private
def user_is_bidder?
user_bids.any?
end
def user_is_winning_bidder?
auction.bids.any? && lowest_user_bid == auction.lowest_bid
end
def lowest_user_bid
user_bids.order(amount: :asc).first
end
def user_bids
auction.bids.where(bidder: current_user)
end
def highlighted_bid
@_highlighted_bid ||=
HighlightedBid.new(auction: auction, user: current_user).find
end
def for_small_business?
AuctionThreshold.new(auction).small_business?
end
def status_presenter
@_status_presenter ||= StatusPresenterFactory.new(auction).create
end
def available?
auction_status.available?
end
def over?
auction_status.over?
end
def auction_status
AuctionStatus.new(auction)
end
end