Method: OpenGraphReader::Object::DSL#datetime

Defined in:
lib/open_graph_reader/object/dsl/types.rb

#datetime(name, options = {}) ⇒ Object

Parameters:

  • name (Symbol)

    the name of the property in the current namespace

  • options ({Symbol => Bool, Class, Array<String>}) (defaults to: {})

    additional options

Options Hash (options):

  • :required (Bool) — default: false

    Make the property required.

  • :collection (Bool) — default: false

    This property can occur multiple times.

  • :to (Class)

    This property maps to the given object (optional). belongs to the given verticals of the object (optional).

  • :verticials (Array<String>)

    This property

  • :downcase (Bool) — default: false

    Normalize the contents case to lowercase.



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/open_graph_reader/object/dsl/types.rb', line 80

define_type :datetime do |value, options|
  begin
    if OpenGraphReader.config.guess_datetime_format
      DateTime.parse value
    else
      DateTime.iso8601 value
    end
  rescue ArgumentError
    next unless options[:required] || !OpenGraphReader.config.discard_invalid_optional_properties
    raise InvalidObjectError, "ISO8601 datetime expected, but was #{value.inspect}"
  end
end