This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
auction_view_model.rb
149 lines (127 loc) · 2.82 KB
/
auction_view_model.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class AuctionViewModel < Struct.new(:current_user, :auction_record)
include ActionView::Helpers::NumberHelper
delegate(
:auction_rules_href,
:available?,
:bid_count,
:bids,
:bids?,
:created_at,
:delivery_deadline,
:eligibility,
:end_datetime,
:expiring?,
:formatted_delivery_deadline,
:formatted_end_time,
:formatted_start_time,
:formatted_type,
:future?,
:highlighted_bid_label,
:html_description,
:html_description,
:html_summary,
:relative_time_left,
:relative_start_time,
:id,
:issue_url,
:over?,
:partial_path,
:read_attribute_for_serialization,
:show_bids?,
:small_business?,
:start_datetime,
:start_price,
:summary,
:title,
:to_param,
:type,
:updated_at,
:lowest_bid,
:veiled_bids,
to: :auction
)
delegate(
:amount,
to: :highlighted_bid,
prefix: true
)
delegate(
:label,
:label_class,
:status_text,
:tag_data_label_2,
:tag_data_value_status,
:tag_data_value_2,
to: :status_presenter
)
def user_can_bid?
auction.user_can_bid?(current_user)
end
def highlighted_bid
auction.highlighted_bid(current_user)
end
def show_bid_button?
user_can_bid? || current_user.nil?
end
def highlighted_bid_amount_as_currency
number_to_currency(highlighted_bid_amount)
end
def highlighted_bidder_name
highlighted_bid.bidder_name
end
def user_is_bidder?
user_bids_obj.bid?
end
def user_is_winning_bidder?
# FIXME: who is calling this?
return false unless auction.bids?
current_user.id == auction.winning_bidder_id
end
def user_bids
user_bids_obj.bids
end
def lowest_user_bid
user_bids_obj.lowest_bid
end
def lowest_user_bid_amount
user_bids_obj.lowest_bid_amount
end
def user_bid_amount_as_currency
number_to_currency(lowest_user_bid_amount)
end
def auction_type
auction.formatted_type
end
def index_bid_summary_partial
auction.partial_path('index_bid_summary')
end
def highlighted_bid_info_partial
auction.partial_path('highlighted_bid_info', 'bids')
end
private
def auction
@auction ||= AuctionPresenter.new(auction_record)
end
def status_presenter_class
status_name = if expiring?
'Expiring'
elsif over?
'Over'
elsif future?
'Future'
else
'Open'
end
"::AuctionStatus::#{status_name}ViewModel".constantize
end
def status_presenter
@status_presenter ||= status_presenter_class.new(self)
end
def user_bids_obj
if current_user.nil?
UserBidsViewModel::Null.new
else
@user_bids_obj ||= UserBidsViewModel.new(current_user, auction.bids)
end
end
end