Class: Hash
Overview
Cast a hash to an id.
Instance Method Summary collapse
-
#to_date_id ⇒ Object
Cast me to a date id by parsing fields for year, month, day.
Instance Method Details
#to_date_id ⇒ Object
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"
13 14 15 16 17 18 19 20 |
# File 'lib/sixarm_ruby_to_id/hash.rb', line 13 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 |