|
|
@ -1,14 +1,14 @@ |
|
|
|
class Form |
|
|
|
class Form |
|
|
|
attr_reader :form_definition, :sections, :subsections, :pages, :questions, |
|
|
|
attr_reader :form_definition, :sections, :subsections, :pages, :questions, |
|
|
|
:start_year, :end_year, :type, :name |
|
|
|
:start_date, :end_date, :type, :name |
|
|
|
|
|
|
|
|
|
|
|
def initialize(form_path, name) |
|
|
|
def initialize(form_path, name) |
|
|
|
raise "No form definition file exists for given year".freeze unless File.exist?(form_path) |
|
|
|
raise "No form definition file exists for given year".freeze unless File.exist?(form_path) |
|
|
|
|
|
|
|
|
|
|
|
@form_definition = JSON.parse(File.open(form_path).read) |
|
|
|
@form_definition = JSON.parse(File.open(form_path).read) |
|
|
|
@name = name |
|
|
|
@name = name |
|
|
|
@start_year = form_definition["start_year"] |
|
|
|
@start_date = form_definition["start_date"] |
|
|
|
@end_year = form_definition["end_year"] |
|
|
|
@end_date = form_definition["end_date"] |
|
|
|
@type = form_definition["form_type"] |
|
|
|
@type = form_definition["form_type"] |
|
|
|
@sections = form_definition["sections"].map { |id, s| Form::Section.new(id, s, self) } |
|
|
|
@sections = form_definition["sections"].map { |id, s| Form::Section.new(id, s, self) } |
|
|
|
@subsections = sections.flat_map(&:subsections) |
|
|
|
@subsections = sections.flat_map(&:subsections) |
|
|
|