Sha256: 3e343231d35c8b1ab0c5a2e5d8ac90ea3d9868548327e4fdf46410d94e885583

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8
require 'jldrill/model/Problem'
require 'jldrill/model/problems/ReadingProblem'
require 'jldrill/model/problems/KanjiProblem'
require 'jldrill/model/problems/MeaningProblem'

module JLDrill
    class ProblemFactory
        PROBLEM_TYPES = ["ReadingProblem", "KanjiProblem", "MeaningProblem"]

        def ProblemFactory.parse(string)
            PROBLEM_TYPES.find_index(string)
        end

        def ProblemFactory.lookup(level)
            return PROBLEM_TYPES[level]
        end

        def ProblemFactory.create(level, item)
            case level
                when 0
                    problem = ReadingProblem.new(item)
                when 1
                    if item.hasKanji?
                        problem = KanjiProblem.new(item)
                    else
                        problem = MeaningProblem.new(item)
                    end
                when 2
                    problem = MeaningProblem.new(item)
                else
                   problem = ReadingProblem.new(item)
             end
            problem.requestedLevel = level
            return problem
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.6.0.1 lib/jldrill/model/problems/ProblemFactory.rb