Class: Quby::Compiler::Outputs::QubyFrontendV2Serializer
- Inherits:
-
Object
- Object
- Quby::Compiler::Outputs::QubyFrontendV2Serializer
- Defined in:
- lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(questionnaire) ⇒ QubyFrontendV2Serializer
constructor
A new instance of QubyFrontendV2Serializer.
- #validations ⇒ Object
Constructor Details
#initialize(questionnaire) ⇒ QubyFrontendV2Serializer
Returns a new instance of QubyFrontendV2Serializer.
7 8 9 |
# File 'lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb', line 7 def initialize(questionnaire) @questionnaire = questionnaire end |
Instance Method Details
#as_json(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb', line 13 def as_json( = {}) { key: key, title: title, language: language || "nl", description: description, shortDescription: short_description, defaultAnswerValue: Services::TransformQuby1ValuesIntoQuby2Values.run!(@questionnaire, default_answer_value), panels: panels, questions: fields.question_hash.as_json, flags: flags, textvars: textvars, validations: validations, visibilityRules: visibility_rules } end |
#validations ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb', line 30 def validations @questionnaire.validations.map do |validation| validation.config.compact .transform_keys{ _1.to_s.camelize(:lower) } .tap do |validation_hsh| # otherwise ruby will put a (?-mix around the regex, which js errors on. validation_hsh['matcher'] = validation_hsh['matcher'].source.to_s if validation_hsh['matcher'] validation_hsh['type'] = 'minimum_date' if validation_hsh['type'] == :minimum && validation_hsh['subtype'] == :date validation_hsh['type'] = 'maximum_date' if validation_hsh['type'] == :maximum && validation_hsh['subtype'] == :date end.as_json end end |