Class: Humidifier::Props::TimestampProp

Inherits:
Base
  • Object
show all
Defined in:
lib/humidifier/props/timestamp_prop.rb

Overview

A timestamp (ISO 8601) property

Constant Summary

Constants inherited from Base

Base::WHITELIST

Instance Attribute Summary

Attributes inherited from Base

#key, #name, #spec, #substructs

Instance Method Summary collapse

Methods inherited from Base

#documentation, #initialize, #required?, #to_cf, #update_type, #whitelisted_value?

Constructor Details

This class inherits a constructor from Humidifier::Props::Base

Instance Method Details

#convert(value) ⇒ Object

converts the value through DateTime.parse(value) unless it is valid



8
9
10
11
12
13
14
15
# File 'lib/humidifier/props/timestamp_prop.rb', line 8

def convert(value)
  if valid?(value) || !value.is_a?(String)
    value
  else
    puts "WARNING: Property #{name} should be a Date or Time"
    DateTime.parse(value)
  end
end

#valid?(value) ⇒ Boolean

true if it is whitelisted, a Time, or a Date

Returns:

  • (Boolean)


18
19
20
# File 'lib/humidifier/props/timestamp_prop.rb', line 18

def valid?(value)
  whitelisted_value?(value) || value.is_a?(Time) || value.is_a?(Date)
end