Sha256: 21e4adfcb2ada549990fb95b2464ebb273866bb79f6fd9ec0c5d37ebc5d0e9da

Contents?: true

Size: 530 Bytes

Versions: 6

Compression:

Stored size: 530 Bytes

Contents

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

# Cast a hash to an id.
#
class Hash

  # Cast me to a date id by parsing fields for year, month, day.
  #
  #    hash = {year: "2000", month: "12", day: "31"}
  #    hash.to_date_id
  #    #=> "2000-12-31"
  #
  def to_date_id
    year  = self["year"]  || self[:year]
    month = self["month"] || self[:month]
    day   = self["day"]   || self[:day]
    year && year!="" && month && month!="" && day && day!="" \
    ? sprintf("%4.4d-%2.2d-%2.2d", year.to_i, month.to_i, day.to_i) \
    : nil
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sixarm_ruby_to_id-2.0.0 lib/sixarm_ruby_to_id/hash.rb
sixarm_ruby_to_id-1.1.3 lib/sixarm_ruby_to_id/hash.rb
sixarm_ruby_to_id-1.1.2 lib/sixarm_ruby_to_id/hash.rb
sixarm_ruby_to_id-1.1.1 lib/sixarm_ruby_to_id/hash.rb
sixarm_ruby_to_id-1.1.0 lib/sixarm_ruby_to_id/hash.rb
sixarm_ruby_to_id-1.0.9 lib/sixarm_ruby_to_id/hash.rb