Sha256: 4eaf2c3254983d46681474df4ff685b20803df8f2627c31e661f1fc7cea3653d
Contents?: true
Size: 1.2 KB
Versions: 5
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module Journal class Section attr_accessor :key, :title, :questions, :answers ## ## 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'] @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 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 else @answers[question.key] = question.ask end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems