Created
February 12, 2016 20:30
-
-
Save adelevie/93db9b87c4d5de53e0d9 to your computer and use it in GitHub Desktop.
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
class AuctionQuery | |
def initialize(relation = Auction.all) | |
@relation = relation | |
end | |
def delivery_deadline_expired(relation = @relation) | |
relation.where!('delivery_deadline < ?', Time.zone.now) | |
end | |
def accepted(relation = @relation) | |
relation.where(result: accepted_enum) | |
end | |
def delivered(relation = @relation) | |
relation.where.not(delivery_url: [nil, ""]) | |
end | |
def cap_submitted(relation = @relation) | |
relation.where.not(cap_proposal_url: [nil, ""]) | |
end | |
def paid(relation = @relation) | |
relation.where( | |
awardee_paid_status: paid_enum | |
) | |
end | |
def not_paid(relation = @relation) | |
relation.where( | |
awardee_paid_status: not_paid_enum | |
) | |
end | |
def complete_and_successful | |
relation = delivery_deadline_expired(@relation) | |
relation = delivered(relation) | |
relation = accepted(relation) | |
relation = cap_submitted(relation) | |
relation = paid(relation) | |
relation | |
end | |
def payment_pending | |
relation = delivery_deadline_expired(@relation) | |
relation = delivered(relation) | |
relation = accepted(relation) | |
relation = cap_submitted(relation) | |
relation = not_paid(relation) | |
relation | |
end | |
private | |
def paid_enum | |
Auction.awardee_paid_statuses['paid'] | |
end | |
def not_paid_enum | |
Auction.awardee_paid_statuses['not_paid'] | |
end | |
def accepted_enum | |
Auction.results['accepted'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment