Sha256: fe0ee65ebab483310fea4b9f4931d4782ff4cec8f53458fd3b23fd22ed4b1d27

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

# -*- coding: utf-8 -*-

# Adds a method for copyright period
# @author Takaaki Kato <takaaki.kato@gmail.com>
module CopyrightHelper
  # Returns copyright period in years
  # @example When the argument is the year of now
  #   copyright_years(2009) #=> "2009"
  # @example When the argument if before of this year
  #   copyright_years(1997) #=> "1997-2009"
  # @param [#is_a?(Integer)]
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
copyright-0.1.3 lib/copyright_helper.rb