This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
475 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class BidStatusPresenterFactory | ||
attr_reader :auction, :user | ||
|
||
def initialize(auction:, user:) | ||
@auction = auction | ||
@user = user | ||
end | ||
|
||
def create | ||
if future? | ||
future_message | ||
elsif over? | ||
over_message | ||
else | ||
available_message | ||
end | ||
end | ||
|
||
private | ||
|
||
def available_message | ||
if admin? | ||
BidStatusPresenter::AvailableUserIsAdmin.new(auction: auction) | ||
elsif guest? | ||
BidStatusPresenter::AvailableUserIsGuest.new(auction: auction) | ||
elsif auction.type == 'reverse' | ||
BidStatusPresenter::AvailableUserIsWinningBidder.new(bid_amount: lowest_user_bid.try(:amount)) | ||
else # sealed bid, user is bidder | ||
BidStatusPresenter::AvailableSealedUserIsBidder.new(bid: lowest_user_bid) | ||
end | ||
end | ||
|
||
def future_message | ||
if admin? | ||
BidStatusPresenter::FutureUserIsAdmin.new(auction: auction) | ||
elsif guest? | ||
BidStatusPresenter::FutureUserIsGuest.new(auction: auction) | ||
else | ||
BidStatusPresenter::FutureUserIsVendor.new(auction: auction) | ||
end | ||
end | ||
|
||
def over_message | ||
if user_is_winning_bidder? | ||
BidStatusPresenter::OverUserIsWinner.new | ||
elsif user_is_bidder? | ||
BidStatusPresenter::OverUserIsBidder.new | ||
elsif auction.bids.any? | ||
BidStatusPresenter::OverWithBids.new | ||
else | ||
BidStatusPresenter::OverNoBids.new | ||
end | ||
end | ||
|
||
def admin? | ||
user.decorate.admin? | ||
end | ||
|
||
def guest? | ||
user.is_a?(Guest) | ||
end | ||
|
||
def over? | ||
auction_status.over? | ||
end | ||
|
||
def available? | ||
auction_status.available? | ||
end | ||
|
||
def future? | ||
auction_status.future? | ||
end | ||
|
||
def auction_status | ||
AuctionStatus.new(auction) | ||
end | ||
|
||
def user_is_winning_bidder? | ||
user_bids.any? && lowest_user_bid == auction.lowest_bid | ||
end | ||
|
||
def user_is_bidder? | ||
user_bids.any? | ||
end | ||
|
||
def lowest_user_bid | ||
user_bids.order(amount: :asc).first | ||
end | ||
|
||
def user_bids | ||
auction.bids.where(bidder: user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class C2StatusPresenterFactory | ||
attr_reader :auction | ||
|
||
def initialize(auction:) | ||
@auction = auction | ||
end | ||
|
||
def create | ||
if auction.c2_approval_status == 'not_requested' | ||
C2StatusPresenter::C2ApprovalNotRequested.new(auction: auction) | ||
else | ||
C2StatusPresenter::C2Pending.new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.