Module: CopyrightHelper

Defined in:
lib/copyright_helper.rb

Overview

Adds a method for copyright period

Author:

Instance Method Summary collapse

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_helper.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 since > Time.new.year
  if since == Time.new.year
    "#{since}"
  else
    "#{since}-#{Time.new.year}"
  end
end