Sha256: 1888d29b5593f76f79b2c1719d2669a479b79afcc0032bfe02d9227e364c6b1c

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 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.1 lib/copyright_helper.rb