Class: GovUkDateFields::FormFields

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::TagHelper
Defined in:
lib/gov_uk_date_fields/form_fields.rb

Constant Summary collapse

DATE_SEGMENTS =
{
  day:    '_dd',
  month:  '_mm',
  year:   '_yyyy',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(form, object_name, attribute, options = {}) ⇒ FormFields

Returns a new instance of FormFields.



14
15
16
17
18
19
20
21
22
23
# File 'lib/gov_uk_date_fields/form_fields.rb', line 14

def initialize(form, object_name, attribute, options={})
  @form               = form
  @object             = form.object
  @object_name        = object_name
  @attribute          = attribute
  @options            = options
  @day_value          = @object.send("#{@attribute}_dd")&.gsub(/\D/, '')
  @month_value        = @object.send("#{@attribute}_mm")&.gsub(/\D/, '')
  @year_value         = @object.send("#{@attribute}_yyyy")&.gsub(/\D/, '')
end

Instance Method Details

#outputObject



29
30
31
# File 'lib/gov_uk_date_fields/form_fields.rb', line 29

def output
  raw_output.html_safe
end

#raw_outputObject



25
26
27
# File 'lib/gov_uk_date_fields/form_fields.rb', line 25

def raw_output
  generate_input_fields
end