Class: Reji::InvoiceLineItem
- Inherits:
-
Object
- Object
- Reji::InvoiceLineItem
- Defined in:
- lib/reji/invoice_line_item.rb
Instance Attribute Summary collapse
-
#invoice ⇒ Object
readonly
Get the Stripe model instance.
Instance Method Summary collapse
-
#as_stripe_invoice_line_item ⇒ Object
Get the underlying Stripe invoice line item.
-
#both_inclusive_and_exclusive_tax? ⇒ Boolean
Determine if the line item has both inclusive and exclusive tax.
-
#end_date ⇒ Object
Get a human readable date for the end date.
-
#exclusive_tax_percentage ⇒ Object
Get the total percentage of the default exclusive tax for the invoice line item.
-
#inclusive_tax_percentage ⇒ Object
Get the total percentage of the default inclusive tax for the invoice line item.
-
#initialize(invoice, item) ⇒ InvoiceLineItem
constructor
A new instance of InvoiceLineItem.
-
#method_missing(key) ⇒ Object
Dynamically access the Stripe invoice line item instance.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#start_date ⇒ Object
Get a human readable date for the start date.
-
#subscription? ⇒ Boolean
Determine if the invoice line item is for a subscription.
-
#tax_rates? ⇒ Boolean
Determine if the invoice line item has tax rates.
-
#total ⇒ Object
Get the total for the invoice line item.
Constructor Details
#initialize(invoice, item) ⇒ InvoiceLineItem
Returns a new instance of InvoiceLineItem.
5 6 7 8 |
# File 'lib/reji/invoice_line_item.rb', line 5 def initialize(invoice, item) @invoice = invoice @item = item end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
Dynamically access the Stripe invoice line item instance.
63 64 65 |
# File 'lib/reji/invoice_line_item.rb', line 63 def method_missing(key) @item[key] end |
Instance Attribute Details
#invoice ⇒ Object (readonly)
Get the Stripe model instance.
55 56 57 |
# File 'lib/reji/invoice_line_item.rb', line 55 def invoice @invoice end |
Instance Method Details
#as_stripe_invoice_line_item ⇒ Object
Get the underlying Stripe invoice line item.
58 59 60 |
# File 'lib/reji/invoice_line_item.rb', line 58 def as_stripe_invoice_line_item @item end |
#both_inclusive_and_exclusive_tax? ⇒ Boolean
Determine if the line item has both inclusive and exclusive tax.
16 17 18 |
# File 'lib/reji/invoice_line_item.rb', line 16 def both_inclusive_and_exclusive_tax? inclusive_tax_percentage > 0 && exclusive_tax_percentage > 0 end |
#end_date ⇒ Object
Get a human readable date for the end date.
45 46 47 |
# File 'lib/reji/invoice_line_item.rb', line 45 def end_date subscription? ? Time.zone.at(@item.period.end).strftime('%b %d, %Y') : nil end |
#exclusive_tax_percentage ⇒ Object
Get the total percentage of the default exclusive tax for the invoice line item.
28 29 30 31 32 |
# File 'lib/reji/invoice_line_item.rb', line 28 def exclusive_tax_percentage return calculate_tax_percentage_by_tax_amount(false) if @invoice.not_tax_exempt? calculate_tax_percentage_by_tax_rate(false) end |
#inclusive_tax_percentage ⇒ Object
Get the total percentage of the default inclusive tax for the invoice line item.
21 22 23 24 25 |
# File 'lib/reji/invoice_line_item.rb', line 21 def inclusive_tax_percentage return calculate_tax_percentage_by_tax_amount(true) if @invoice.not_tax_exempt? calculate_tax_percentage_by_tax_rate(true) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
67 68 69 |
# File 'lib/reji/invoice_line_item.rb', line 67 def respond_to_missing?(method_name, include_private = false) super end |
#start_date ⇒ Object
Get a human readable date for the start date.
40 41 42 |
# File 'lib/reji/invoice_line_item.rb', line 40 def start_date subscription? ? Time.zone.at(@item.period.start).strftime('%b %d, %Y') : nil end |
#subscription? ⇒ Boolean
Determine if the invoice line item is for a subscription.
50 51 52 |
# File 'lib/reji/invoice_line_item.rb', line 50 def subscription? @item.type == 'subscription' end |
#tax_rates? ⇒ Boolean
Determine if the invoice line item has tax rates.
35 36 37 |
# File 'lib/reji/invoice_line_item.rb', line 35 def tax_rates? @invoice.not_tax_exempt? ? !@item.tax_amounts.empty? : !@item.tax_rates.empty? end |
#total ⇒ Object
Get the total for the invoice line item.
11 12 13 |
# File 'lib/reji/invoice_line_item.rb', line 11 def total format_amount(@item.amount) end |