Class: Spout::Models::Form
Instance Attribute Summary collapse
-
#code_book ⇒ Object
Returns the value of attribute code_book.
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #deploy_params ⇒ Object
-
#initialize(file_name, dictionary_root) ⇒ Form
constructor
A new instance of Form.
Methods inherited from Record
Constructor Details
#initialize(file_name, dictionary_root) ⇒ Form
Returns a new instance of Form.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spout/models/form.rb', line 17 def initialize(file_name, dictionary_root) @errors = [] @id = file_name.to_s.gsub(/^(.*)\/|\.json$/, "").downcase @folder = file_name.to_s.gsub(/^#{dictionary_root}\/forms\/|#{@id}\.json$/, "") json = begin JSON.parse(File.read(file_name, encoding: "utf-8")) rescue => e form_name = file_name.to_s.gsub(/^(.*)\/|\.json$/, "").downcase @errors << "Error Parsing #{form_name}.json: #{e.}" nil end if json.is_a? Hash %w(display_name code_book).each do |method| instance_variable_set("@#{method}", json[method]) end @errors << "'id': #{json['id'].inspect} does not match filename #{@id.inspect}" if @id != json["id"] elsif json @errors << "Form must be a valid hash in the following format: {\n\"id\": \"FORM_ID\",\n \"display_name\": \"FORM DISPLAY NAME\",\n \"code_book\": \"FORMPDF.pdf\"\n}" end end |
Instance Attribute Details
#code_book ⇒ Object
Returns the value of attribute code_book.
14 15 16 |
# File 'lib/spout/models/form.rb', line 14 def code_book @code_book end |
#display_name ⇒ Object
Returns the value of attribute display_name.
14 15 16 |
# File 'lib/spout/models/form.rb', line 14 def display_name @display_name end |
#errors ⇒ Object
Returns the value of attribute errors.
15 16 17 |
# File 'lib/spout/models/form.rb', line 15 def errors @errors end |
#folder ⇒ Object
Returns the value of attribute folder.
14 15 16 |
# File 'lib/spout/models/form.rb', line 14 def folder @folder end |
#id ⇒ Object
Returns the value of attribute id.
14 15 16 |
# File 'lib/spout/models/form.rb', line 14 def id @id end |