lib/uk_financial_year.rb in fyuk-0.1.0 vs lib/uk_financial_year.rb in fyuk-0.1.1
- old
+ new
@@ -15,10 +15,11 @@
# creates a new UkFinancialYear from a string in the form '2000/01'
# @param [String] s the two years of the financial year in the form
# of the first year as four digits, a '/', then the last year as
# two digits
+ # @raise [RuntimeError] if the string cannot be parsed to a financial year
# @return [UkFinancialYear] the financial year specified by the string
def UkFinancialYear.from_s s
if /^(?<year1>\d{4})\/(?<year2>\d{2})$/ =~ s
year1 = year1.to_i
year1_century = year1 / 100
@@ -48,10 +49,22 @@
# @return [Boolean] to indicate if the date is within the financial year
def include? date
@range.include? date
end
+ # returns the next financial year
+ # @return [UkFinancialYear] the next financial year
+ def next
+ UkFinancialYear.new self.first_day.next_year
+ end
+
+ # returns the previous financial year
+ # @return [UkFinancialYear] the previous financial year
+ def previous
+ UkFinancialYear.new self.first_day.prev_year
+ end
+
# returns string representation of the financial year in the form '2000/01'
# @return [String] representation in the form of the first year as four
# digits, a '/', then the last year as two digits
def to_s
"#{self.first_day.year}/#{self.last_day.year.to_s[-2..-1]}"
@@ -60,10 +73,10 @@
# equality method
def ==(other)
self.first_day == other.first_day
end
- # lesser financial years are those which occur first in time
+ # lesser financial years are those which occur earliest
def <=>(other)
self.first_day <=> other.first_day
end
private
\ No newline at end of file