Class: Vcard::V4_0::PropertyValue::Date

Inherits:
Vobject::PropertyValue show all
Includes:
Comparable
Defined in:
lib/vobject/vcard/v4_0/propertyvalue.rb

Instance Attribute Summary

Attributes inherited from Vobject::PropertyValue

#errors, #norm, #type, #value

Instance Method Summary collapse

Methods inherited from Vobject::PropertyValue

#name, #to_norm

Constructor Details

#initialize(val) ⇒ Date

Returns a new instance of Date.



154
155
156
157
158
159
160
161
162
# 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

Instance Method Details

#<=>(another) ⇒ Object



150
151
152
# File 'lib/vobject/vcard/v4_0/propertyvalue.rb', line 150

def <=>(another)
  value[:date] <=> another.value[:date]
end

#to_hashObject



182
183
184
185
186
187
188
# 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_sObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# 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