Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created February 12, 2016 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelevie/93db9b87c4d5de53e0d9 to your computer and use it in GitHub Desktop.
Save adelevie/93db9b87c4d5de53e0d9 to your computer and use it in GitHub Desktop.
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