Skip to content

Instantly share code, notes, and snippets.

@stephenrichards
Created December 12, 2018 10:25
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 stephenrichards/589faa4da647b79cb29d220daecbabd2 to your computer and use it in GitHub Desktop.
Save stephenrichards/589faa4da647b79cb29d220daecbabd2 to your computer and use it in GitHub Desktop.
SwipeOutService used by controller
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