Skip to content

Instantly share code, notes, and snippets.

@valachi
Created April 30, 2013 08:54
Show Gist options
  • Save valachi/5487491 to your computer and use it in GitHub Desktop.
Save valachi/5487491 to your computer and use it in GitHub Desktop.
class RiskFree
....
def get_date(date)
date = orig_date = date.to_date
year = date.year
data = fetch(year)
result = nil
counter = 0
while(!result)
result = data[date]
date-=1 #1 day before
counter+=1
# more than 1 month or out of current year
break if (counter > 30 || date < orig_date.beginning_of_year)
end
return result if result
date = (orig_date - 1.year).end_of_year
RiskFree.new.get_date(date)
end
....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment