Class: Fe::DateField

Inherits:
Question show all
Defined in:
app/models/fe/date_field.rb

Instance Attribute Summary

Attributes inherited from Question

#answers

Instance Method Summary collapse

Methods inherited from Question

#default_label?, #has_response?, #locked?, #required?, #responses, #save_file, #save_response, #set_response

Methods inherited from Element

#all_elements, #conditional_match, #duplicate, #has_response?, #limit, max_label_length, #page_id, #position, #previous_element, #question?, #required?, #reuseable?, #set_conditional_element, #set_position, #update_any_previous_conditional_elements

Instance Method Details

#display_response(answer_sheet = nil) ⇒ Object



32
33
34
# File 'app/models/fe/date_field.rb', line 32

def display_response(answer_sheet = nil)
  return format_date_response(answer_sheet)
end

#format_date_response(answer_sheet = nil) ⇒ Object



36
37
38
39
40
# File 'app/models/fe/date_field.rb', line 36

def format_date_response(answer_sheet = nil)
  r = response(answer_sheet)
  r = r.strftime("%m/%d/%Y") unless r.blank?
  r
end

#ptemplateObject

which view to render this element?



43
44
45
46
47
48
49
# File 'app/models/fe/date_field.rb', line 43

def ptemplate
  if self.style == 'mmyy'
    'fe/date_field_mmyy'
  else
    'fe/date_field'
  end
end

#response(answer_sheet = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/fe/date_field.rb', line 14

def response(answer_sheet = nil)
  r = super
  return nil if r.blank?
  begin
    if r.is_a?(String)
      parts = r.split('/')
      if parts.length == 3
        r = Time.mktime(parts[2], parts[0], parts[1])
      else
        r = Time.parse(r)
      end
    end
  rescue ArgumentError
    r = ''
  end
  r
end

#validation_class(answer_sheet = nil) ⇒ Object



6
7
8
9
10
11
12
# File 'app/models/fe/date_field.rb', line 6

def validation_class(answer_sheet = nil)
  if self.style == 'mmyy'
    'validate-selection ' + super
  else
    'validate-date ' + super
  end
end