class Saru::Anki
Attributes
items[R]
Public Class Methods
new(items)
click to toggle source
# File lib/saru/anki.rb, line 8 def initialize items @items = items end
Public Instance Methods
deck()
click to toggle source
# File lib/saru/anki.rb, line 12 def deck raise NotImplementedError, 'Radicals not supported' if items.first.is_a?(Saru::Radical) @deck ||= ::Anki::Deck.new card_headers: %w(front back tags), card_data: card_data end
generate()
click to toggle source
# File lib/saru/anki.rb, line 19 def generate file_path = "saru_deck_#{timestamp}.txt" deck.generate_deck file: file_path puts "Anki file generated in #{file_path}" end
Private Instance Methods
back_for(item)
click to toggle source
# File lib/saru/anki.rb, line 42 def back_for item case item when Saru::Kanji then "#{item.meaning} —— #{item.important_reading}" when Saru::Vocabulary then "#{item.meaning} —— #{item.kana}" end end
card_data()
click to toggle source
# File lib/saru/anki.rb, line 28 def card_data items.map do |item| { 'front' => item.character, 'back' => back_for(item), 'tags' => item.class.name.split('::').last } end end
timestamp()
click to toggle source
# File lib/saru/anki.rb, line 38 def timestamp @timestamp ||= DateTime.now.strftime("%y%m%d%H%M") end