Last active
March 28, 2016 23:58
-
-
Save perezpaya/d5adb3054b917e97c391 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 CompanyMarketUpdatesService | |
def initialize(notification_job: NotificationJob.new) | |
@notification_job = notification_job | |
end | |
def update(params) | |
Company.find_by_stock_symbol(params[:stock_symbol])&.tap do |company| | |
should_notify = should_notify_stock_price_reduction?(company.stock_price, params[:stock_price]) | |
company.update(params) | |
notify_stock_price_reduction(company) if should_notify | |
end | |
end | |
private | |
def should_notify_stock_price_reduction?(previous_stock_price, current_stock_price) | |
previous_stock_price > current_stock_price | |
end | |
def notify_stock_price_reduction(company) | |
@notification_job.perform(message: "Stock price for #{company.stock_symbol} down to #{company.stock_price}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment