Class: Barker::Import::Yaml

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/barker/import/yaml.rb

Constant Summary

Constants included from Errors

Errors::AlreadyAnsweredError, Errors::AlreadyStartedError, Errors::AnswerNotFoundError, Errors::BarkerError, Errors::FileNotExistError, Errors::HasToRespondToIdError, Errors::HasToRespondToLocaleError, Errors::JokerAlreadyUsedError, Errors::NoCurrentStageError, Errors::NotStartedError, Errors::RecordNotFound, Errors::UnknownJokerError

Class Method Summary collapse

Class Method Details

.process(path) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/barker/import/yaml.rb', line 7

def self.process(path)
  raise FileNotExistError unless File.exist? path

  questions = YAML.load(File.read(path))

  questions.map do |id, question|
    answers = question["answers"].map do |id, answer|
      Answer.new(id, answer["label"], answer["correct"])
    end
    Question.new(id, question["label"], answers)
  end
end