Class: Questionnaire
- Inherits:
-
Object
- Object
- Questionnaire
- Defined in:
- lib/questionnaire.rb
Overview
Simple model to hold sets of questions and answers.
Class Method Summary collapse
Class Method Details
.config ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/questionnaire.rb', line 6 def self.config @@config ||= begin file = File.join(Rails.root, "config/questionnaire.yml") YAML::load(File.open(file)) end rescue raise "Config file is not found. Please use 'rails g questionnaire_config'." end |
.find_random_question ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/questionnaire.rb', line 15 def self.find_random_question questions = config['questions']['en']#[I18n.locale.to_s] q = questions.keys[rand(questions.size)].dup interval = (config['interval'] || 50).to_i formula = questions[q].dup first_number = rand(interval) last_number = rand(interval) formula.gsub!('$1', first_number.to_s) formula.gsub!('$2', last_number.to_s) result = eval(formula) q.gsub!('$1', HumaneInteger.new(first_number).to_english) q.gsub!('$2', HumaneInteger.new(last_number).to_english) [q, result] end |