class Vcard::V4_0::PropertyValue::Date

Public Class Methods

new(val) click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 154
def initialize(val)
  self.value = val.clone
  self.type = "date"
  # fill in unspecified month && year && date; only for purposes of comparison
  val[:year] = sprintf("%04d", ::Date.today.year) unless val.has_key?(:year)
  val[:month] = sprintf("%02d", ::Date.today.month) unless val.has_key?(:month)
  val[:day] = sprintf("%02d", ::Date.today.day) unless val.has_key?(:day)
  value[:date] = ::Time.utc(val[:year], val[:month], val[:day])
end

Public Instance Methods

<=>(another) click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 150
def <=>(another)
  value[:date] <=> another.value[:date]
end
to_hash() click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 182
def to_hash
  ret = {}
  ret[:year] = value[:year] if value[:year]
  ret[:month] = value[:month] if value[:month]
  ret[:day] = value[:day] if value[:day]
  ret
end
to_s() click to toggle source
# File lib/vobject/vcard/v4_0/propertyvalue.rb, line 164
def to_s
  ret = ""
  ret << if value[:year]
           value[:year]
         else
           "--"
         end
  if value[:month]
    ret << value[:month]
  elsif value[:day]
    ret << "-"
  end
  if value[:day]
    ret << value[:day]
  end
  ret
end