Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>anki-import</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.radrails.rails.core.railsnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.2) | ||
git (1.2.5) | ||
jeweler (1.5.0.pre5) | ||
bundler (~> 1.0.0) | ||
git (>= 1.2.5) | ||
rake | ||
rake (0.8.7) | ||
rcov (0.9.9) | ||
rspec (2.0.0) | ||
rspec-core (= 2.0.0) | ||
rspec-expectations (= 2.0.0) | ||
rspec-mocks (= 2.0.0) | ||
rspec-core (2.0.0) | ||
rspec-expectations (2.0.0) | ||
diff-lcs (>= 1.1.2) | ||
rspec-mocks (2.0.0) | ||
rspec-core (= 2.0.0) | ||
rspec-expectations (= 2.0.0) | ||
sqlite3-ruby (1.3.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (~> 1.0.0) | ||
jeweler (~> 1.5.0.pre5) | ||
rcov | ||
rspec (~> 2.0.0) | ||
sqlite3-ruby (>= 1.3.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
= anki_importer | ||
|
||
Description goes here. | ||
Imports data from Anki deck databases. | ||
|
||
== Contributing to anki_importer | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'anki/importer/deck.rb' | ||
require 'anki/importer/model.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'active_support/core_ext' | ||
require 'sqlite3' | ||
|
||
# :nodoc: namespace | ||
module Anki | ||
# :nodoc: namespace | ||
module Importer | ||
|
||
# The root of the Anki object graph. | ||
class Deck | ||
# Array of models. | ||
attr_reader :models | ||
|
||
# Reads an Anki deck database. | ||
# | ||
# Args: | ||
# deck_path:: path to an Anki deck on the filesystem | ||
# | ||
# Returns a deck. | ||
def self.from_file(deck_path) | ||
deck_db = SQLite3::Database.new deck_path | ||
from_db deck_db | ||
end | ||
|
||
# Reads an Anki deck database. | ||
# | ||
# Args: | ||
# deck_db:: a Sqlite3::Datbase | ||
# | ||
# Returns a deck. | ||
def self.from_db(deck_db) | ||
deck = self.new | ||
deck.models = Model.from_db deck_db | ||
|
||
deck | ||
end | ||
|
||
# :nodoc: private | ||
def initialize | ||
end | ||
|
||
# :nodoc: private | ||
def models=(new_models) | ||
@models = new_models | ||
@models_by_id = new_models.index_by(&:anki_id) | ||
end | ||
# :nodoc: private | ||
attr_reader :models_by_id | ||
end # class Anki::Importer::Deck | ||
end # namespace Anki::Importer | ||
end # namespace Anki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'sqlite3' | ||
|
||
# :nodoc: namespace | ||
module Anki | ||
# :nodoc: namespace | ||
module Importer | ||
|
||
# Schema for Anki cards. | ||
# | ||
# A deck can have multiple models. | ||
class Model | ||
# Name assigned in the Anki UI. | ||
attr_reader :name | ||
# Generally empty. | ||
attr_reader :description | ||
# Assigned in the Anki UI. Space-separated string. | ||
attr_reader :tags | ||
# Unique ID in the models table. | ||
attr_reader :anki_id | ||
|
||
# Reads the models from an Anki deck. | ||
# | ||
# Args: | ||
# deck_db:: a Sqlite3::Datbase | ||
# | ||
# Returns an array of Model instances. | ||
def self.from_db(deck_db) | ||
query = 'SELECT id, name, description, tags, features FROM models' | ||
models = deck_db.execute(query).map do |anki_id, name, description, tags, | ||
features| | ||
self.new anki_id, name, description, tags, features | ||
end | ||
end | ||
|
||
# :nodoc: private | ||
def initialize(anki_id, name, description, tags, features) | ||
@anki_id = anki_id | ||
@name = name | ||
@description = description | ||
@tags = tags | ||
@features = features | ||
end | ||
end # class Anki::Importer::Model | ||
end # namespace Anki::Importer | ||
end # namespace Anki |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe "AnkiImporter" do | ||
it "fails" do | ||
fail "hey buddy, you should probably rename this file and start specing for real" | ||
describe "anki-importer" do | ||
let(:deck) do | ||
deck_path = File.join File.dirname(__FILE__), 'fixtures', 'deck.anki' | ||
Anki::Importer::Deck.from_file deck_path | ||
end | ||
|
||
describe 'Deck' do | ||
it 'should have a Model' do | ||
deck.should have(1).model | ||
end | ||
end | ||
|
||
describe 'Model' do | ||
let(:model) { deck.models.first } | ||
|
||
it 'should extract the name correctly' do | ||
model.name.should == 'CSS Color' | ||
end | ||
|
||
it 'should extract tags correctly' do | ||
model.tags.should == 'css html color' | ||
end | ||
end | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters