Sha256: 24f7f3a7995fdd445ac43e093768145b12e319fa41427d1164a9a927358acda6

Contents?: true

Size: 624 Bytes

Versions: 4

Compression:

Stored size: 624 Bytes

Contents

# encoding: UTF-8

module Analects
  class HskLoader
    extend Forwardable
    include Enumerable

    FIELDS = [:level, :simplified, :traditional, :pinyin]

    class HskEntry < Struct.new(:library, *FIELDS)
      def cedict
        @cedict ||= library.cedict.loader.find_by(
          traditional: traditional,
          simplified: simplified,
        )
      end
    end

    def_delegators :@contents, :each

    def initialize(io, library)
      @contents = CSV(io.read).map do |level, simplified, traditional, pinyin|
        HskEntry.new(library, level, simplified, traditional, pinyin)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
analects-0.4.2 lib/analects/hsk_loader.rb
analects-0.4.1 lib/analects/hsk_loader.rb
analects-0.4.0 lib/analects/hsk_loader.rb
analects-0.3.1 lib/analects/hsk_loader.rb