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

Class Method Summary collapse

Class Attribute Details

.default_localeObject

The default locale, as a symbol.



14
15
16
# File 'lib/questiongenerator.rb', line 14

def default_locale
  @default_locale
end

.question_base_pathObject

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.

Parameters:

  • :locale (Symbol)

    The target locale



33
34
35
36
# File 'lib/questiongenerator.rb', line 33

def compile(locale: @default_locale)
  questions = YAML.load_file(File.expand_path("#{locale}.yml", @question_base_path))
  @compiled[locale] = build(questions)
end

.generate(locale: @default_locale, prefix: "", suffix: "?") ⇒ String

Generates a new question.

Parameters:

  • options (Hash)

    A customizable set of options.

  • :locale (Symbol)

    The target locale

  • :prefix (String)

    Prefix of the question, e.g. ‘¿’

  • :suffix (String)

    Suffix of the question, e.g. ‘ ?’

Returns:

  • (String)

    String containing the generated 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