Class: SimpleInvoice::Emailer::TextBody
- Inherits:
-
Object
- Object
- SimpleInvoice::Emailer::TextBody
- Defined in:
- lib/simple_invoice/emailer/text_body.rb
Instance Method Summary collapse
- #dollars(total_cents) ⇒ String
- #email_body ⇒ String
-
#initialize(invoice, mail_config = MailConfig) ⇒ TextBody
constructor
A new instance of TextBody.
- #invoice_data ⇒ Object
- #line_items_table ⇒ Object
- #postscript ⇒ Object
- #preamble ⇒ Object
- #salutation ⇒ Object
Constructor Details
#initialize(invoice, mail_config = MailConfig) ⇒ TextBody
Returns a new instance of TextBody.
6 7 8 9 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 6 def initialize invoice, mail_config=MailConfig @invoice = invoice @mail_config = mail_config end |
Instance Method Details
#dollars(total_cents) ⇒ String
59 60 61 62 63 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 59 def dollars total_cents dollar = total_cents / 100 cents = total_cents % 100 "$%d.%02d" % [dollar, cents] end |
#email_body ⇒ String
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 12 def email_body salutation + "\n" + "\n" + preamble + "\n" + "\n" + invoice_data + "\n" + "Invoice Items:\n" + line_items_table + "\n" + postscript + "\n" end |
#invoice_data ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 37 def invoice_data list = TextList.new list.add 'Invoice Number', @invoice.invoice_number list.add 'Amount Due', dollars(@invoice.line_items.total) list.add 'Due Date', @invoice.due_date list.to_s end |
#line_items_table ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 45 def line_items_table table = EmailInvoiceTextTable.new @invoice.line_items.to_a.each do |line_item| table.line_item :description => line_item.description, :price => dollars(line_item.price), :quantity => line_item.quantity, :total => dollars(line_item.total) end table.total dollars(@invoice.line_items.total) table.to_s end |
#postscript ⇒ Object
33 34 35 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 33 def postscript "" end |
#preamble ⇒ Object
29 30 31 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 29 def preamble "This email is an invoice for services by #{@mail_config[:organisation_name]}." end |
#salutation ⇒ Object
25 26 27 |
# File 'lib/simple_invoice/emailer/text_body.rb', line 25 def salutation "Dear #{@invoice.contact.name}" end |