asanghi / fiscali

Fiscal Year Date Functions

Home Page:http://asanghi.github.com/fiscali

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to extend the functionality of this gem

jaykilleen opened this issue · comments

Hi,

I am still learning Ruby and Rails. I'd like to define my own method on this that does the following.

Assuming I am in financial year 2014 I can call Date.today.financial_periods and have an array [201501,201502,201503,201504,201505,201506,201507,201508,201509,201510,201511,201512] returned.

Where would I put this to define it?

I have tried creating a new file under my lib directory called fiscali.rb and adding

module RisingSun
  module Fiscali
    def financial_periods
      year = self.financial_year
      financial_periods = []
      (1..12).each do |period|
        period.format("%02d",4)
        financial_periods << period
      end
    end
  end
end

But no luck... 😖

commented

You are on the right track.

First, don't use 'financial_periods' as a variable since it's also your
method name. You can call it anything and it will be returned since it's
the last action in your code.

Second, you added your financial_periods method to the Fiscali module, not
the date module. You should explore how to add this method to the Date
class.

Note that you want to call 'Date.today.financial_periods', so it needs to
live inside Date.
On May 14, 2015 3:08 AM, "Jay Killeen" notifications@github.com wrote:

Hi,

I am still learning Ruby and Rails. I'd like to define my own method on
this that does the following.

Assuming I am in financial year 2014 I can call
Date.today.financial_periods and have an array
[201501,201502,201503,201504,201505,201506,201507,201508,201509,201510,201511,201512]
returned.

Where would I put this to define it?

I have tried creating a new file under my lib directory called fiscali.rb
and adding

module RisingSun
module Fiscali
def financial_periods
year = self.financial_year
financial_periods = .each do |period|
period.format("%02d",4)
financial_periods << period
end
end
endend

But no luck... [image: 😖]


Reply to this email directly or view it on GitHub
#11.

Would still love a pull request if you would find this method useful.