Sha256: 94497de473f48813c37d428c23b95cdd61e3be3c6e2f3b2414fc9c81d7e3bb58
Contents?: true
Size: 1.32 KB
Versions: 5
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true module Journal class Section attr_accessor :key, :title, :questions, :answers, :condition ## ## Initializes the given section. ## ## @param section [Hash] The section as defined in ## configuration ## ## @return [Section] the configured section ## def initialize(section) @key = section["key"] @title = section["title"] @condition = section.key?("condition") ? section["condition"].parse_condition : true @questions = section["questions"].map { |question| Question.new(question) } @questions.delete_if { |q| q.prompt.nil? } @answers = {} ask_questions end ## ## Ask the questions detailed in the 'questions' section of the configuration ## ## @return [Hash] the question responses ## def ask_questions @questions.each do |question| if /\./.match?(question.key) res = @answers keys = question.key.split(".") keys.each_with_index do |key, i| next if i == keys.count - 1 res[key] = {} unless res.key?(key) res = res[key] end res[keys.last] = question.ask(@condition) else @answers[question.key] = question.ask(@condition) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems