Module: QuestionGenerator
- Defined in:
- lib/questiongenerator.rb
Overview
Generates some questions.
Constant Summary collapse
- VERSION =
Version of QuestionGenerator
"1.1.0"
Class Attribute Summary collapse
-
.default_locale ⇒ Object
The default locale, as a symbol.
-
.question_base_path ⇒ Object
The base path to the questions (e.g. ‘/home/nilsding/questions’).
Class Method Summary collapse
-
.compile(locale: @default_locale) ⇒ Object
Compiles all the questions and stores it into the @compiled hash.
-
.generate(locale: @default_locale, prefix: "", suffix: "?") ⇒ String
Generates a new question.
Class Attribute Details
.default_locale ⇒ Object
The default locale, as a symbol.
14 15 16 |
# File 'lib/questiongenerator.rb', line 14 def default_locale @default_locale end |
.question_base_path ⇒ Object
The base path to the questions (e.g. ‘/home/nilsding/questions’).
12 13 14 |
# File 'lib/questiongenerator.rb', line 12 def question_base_path @question_base_path end |
Class Method Details
.compile(locale: @default_locale) ⇒ Object
Compiles all the questions and stores it into the @compiled hash.
33 34 35 36 |
# File 'lib/questiongenerator.rb', line 33 def compile(locale: @default_locale) questions = YAML.load_file(File.("#{locale}.yml", @question_base_path)) @compiled[locale] = build(questions) end |
.generate(locale: @default_locale, prefix: "", suffix: "?") ⇒ String
Generates a new question.
25 26 27 28 29 |
# File 'lib/questiongenerator.rb', line 25 def generate(locale: @default_locale, prefix: "", suffix: "?") compile(locale:) unless @compiled.key?(locale) prefix + @compiled[locale].sample + suffix end |