Class: Castiel::Elements::DateElement

Inherits:
BaseElement show all
Defined in:
lib/castiel/elements/date_element.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(element, context = nil) ⇒ Object



11
12
13
# File 'lib/castiel/elements/date_element.rb', line 11

def evaluate(element, context = nil)
  ::Date.parse(element).to_time
end

#match?(element, context = nil) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/castiel/elements/date_element.rb', line 5

def match?(element, context = nil)
  return false unless element =~ /^\d{4}[-\/]\d{2}[-\/]\d{2}|\d{2}[-\/]\d{2}[-\/]\d{4}$/
  return false unless ::Date.parse(element) rescue nil
  true
end