Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The class FinancialReportMailer uses composition
- # i.e an instance of another class FinancialReportGenerator
- # and it's methods to implement SRP.
- # FinancialReportGenerator generates a report.
- # The report is passed to FinancialReportMailer, where method, deliver
- # is invoked to send the generated report
- class FinancialReportMailer
- def initialize(report, account)
- @report = report
- @account = account
- end
- def deliver
- Mailer.deliver(
- from: 'reporter@example.com',
- to: @account.email,
- subject: 'Financial report',
- body: @report
- )
- end
- end
- class FinancialReportGenerator
- def initialize(transactions)
- @transactions = transactions
- end
- def generate
- @transactions.map { |t| "amount: #{t.amount} type: #{t.type} date: #{t.created_at}"
- }.join("\n")
- end
- end
- report = FinancialReportGenerator.new(transactions).generate
- FinancialReportMailer.new(report, account).deliver
Add Comment
Please, Sign In to add comment