Module: CopyrightYears

Defined in:
lib/copyright.rb

Overview

Adds a method for copyright period

Author:

Instance Method Summary

Instance Method Details

Returns copyright period in years

Examples:

When the argument is the year of now

  copyright_years(2009) #=> "2009"

When the argument if before of this year

  copyright_years(1997) #=> "1997 - 2009"

Parameters:

  • (#is_a?(Integer))

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/copyright.rb', line 12

def copyright_years(since)
  raise ArgumentError, "Argument should be a number" unless since.is_a?(Integer)
  raise ArgumentError, "since should not be a future" if Date.civil(since).year > Date.today.year
  if Date.civil(since).year == Date.today.year
    since.to_s
  else
    "#{since} - #{Date.today.year}"
  end
end