Class: ROI::GrossProfit

Inherits:
Object
  • Object
show all
Defined in:
lib/roi/gross_profit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rentabilities, start_date, end_date) ⇒ GrossProfit

Returns a new instance of GrossProfit.



11
12
13
14
15
# File 'lib/roi/gross_profit.rb', line 11

def initialize(rentabilities, start_date, end_date)
  @rentabilities = rentabilities
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



9
10
11
# File 'lib/roi/gross_profit.rb', line 9

def end_date
  @end_date
end

#rentabilitiesObject (readonly)

Returns the value of attribute rentabilities.



9
10
11
# File 'lib/roi/gross_profit.rb', line 9

def rentabilities
  @rentabilities
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



9
10
11
# File 'lib/roi/gross_profit.rb', line 9

def start_date
  @start_date
end

Instance Method Details

#current_monthObject



17
18
19
20
# File 'lib/roi/gross_profit.rb', line 17

def current_month
  scope_start = WorkDay.next_after(end_date.beginning_of_month, 0)
  format_gross_profit(scope_start, end_date)
end

#current_yearObject



27
28
29
30
# File 'lib/roi/gross_profit.rb', line 27

def current_year
  scope_start = WorkDay.next_after(end_date.beginning_of_year, 0)
  format_gross_profit(scope_start, end_date)
end

#months(amount) ⇒ Object



22
23
24
25
# File 'lib/roi/gross_profit.rb', line 22

def months(amount)
  scope_start = (end_date - amount.months + 1.month).beginning_of_month
  check_gaps_and_format(scope_start, end_date)
end

#portfolioObject



38
39
40
# File 'lib/roi/gross_profit.rb', line 38

def portfolio
  format_gross_profit(start_date, end_date)
end

#years_ago(amount) ⇒ Object



32
33
34
35
36
# File 'lib/roi/gross_profit.rb', line 32

def years_ago(amount)
  scope_end = (end_date - amount.year).end_of_year
  scope_start = scope_end.beginning_of_year
  format_gross_profit(scope_start, scope_end)
end