Class: PR::Fields::DateField

Inherits:
Object
  • Object
show all
Defined in:
lib/pr/fields/date_field.rb

Constant Summary collapse

Format =
'%d/%m/%Y'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = '', options = {}) ⇒ DateField

Returns a new instance of DateField.



7
8
9
# File 'lib/pr/fields/date_field.rb', line 7

def initialize value = '', options = {}
  @value, @options = value, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/pr/fields/date_field.rb', line 10

def options
  @options
end

Instance Method Details

#convertObject



20
21
22
23
24
# File 'lib/pr/fields/date_field.rb', line 20

def convert
  Date.strptime(@value,Format)
rescue ArgumentError
  raise InvalidValue
end

#populate(date) ⇒ Object



16
17
18
# File 'lib/pr/fields/date_field.rb', line 16

def populate date
  @value = date.strftime Format
end

#rawObject



12
13
14
# File 'lib/pr/fields/date_field.rb', line 12

def raw
  @value
end