Sha256: b9431db3875a3182430df4bc6045387718755260c83adc4e2cb433fb86e2c339

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

#!/usr/bin/ruby

# encoding: utf-8
# This script creates a drill file containing all the Jouyou kanji
# ordered by grade and stroke order.

require 'jldrill/model/moji/Kanji'
require 'jldrill/model/items/Vocabulary'
require 'jldrill/model/Item'
require 'jldrill/model/Quiz/Quiz'
require 'jldrill/model/Config'

module JLDrill

    def JLDrill::kanjiToItem(kanji)
        char = kanji.character
        vocab = Vocabulary.new(kanji.character, kanji.readings.join(", "), 
                               kanji.meanings, ["G#{kanji.grade}"])
        return Item.create(vocab.to_s)
    end

    quiz = Quiz.new
    quiz.name = "Kanji"
    kanjiFile = File.join(Config::DATA_DIR, "dict/rikaichan/kanji.dat")
    kanjiList = KanjiList.fromFile(kanjiFile)
    1.upto(12) do |grade|
        kanjiList.select do |kanji|
            kanji.grade == grade
        end.sort do |x, y|
            x.strokes <=> y.strokes
        end.each do |kanji|
            quiz.contents.addItem(JLDrill::kanjiToItem(kanji), 0)
        end
    end
    quizString = quiz.saveToString
    print quizString
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.6.0.1 bin/createKanjiDrill