Created
December 12, 2018 10:25
-
-
Save stephenrichards/589faa4da647b79cb29d220daecbabd2 to your computer and use it in GitHub Desktop.
SwipeOutService used by controller
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 SwipeOutService | |
delegate :alerts, :to => :fare_calculator | |
def initialize(card, end_station_id) | |
@card = card | |
@end_station = Station.find(end_station_id) | |
@fare_calculator = FareCalculator.new(@card, @end_station) | |
end | |
def call | |
fare = @fare_calculator.calculate | |
if fare > 0 | |
@card.balance -= fare | |
@card.transactions << @fare_calculator.transaction | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment