anki 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/CHANGELOG.md +3 -0
- data/README.md +32 -2
- data/anki.gemspec +0 -1
- data/lib/anki/deck.rb +14 -1
- data/lib/anki/version.rb +1 -1
- data/spec/anki/deck_spec.rb +8 -0
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c21472ccaf55739e044a25afb9ffc66e2752a41
|
4
|
+
data.tar.gz: b21056c3a15d6e8e32408d11f2073e474a21323b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6661f4ae89070e88e122b2dd9d6db74649c630d617cb16dec93eb2c062ea65b5f9d7b5b28affb4e820e5db714428b991d6071414770efdb749a1e1b858a2890
|
7
|
+
data.tar.gz: d1cd3de9ecd1f9e7896f8b575ae9fa49bcafc4e7b2f323d64df65e188ba90e8c27e9fe6357330536e68d5fefb0adaed4451691455ec694c2886317c54ab8f1db
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.0.2 (April 20, 2014)
|
4
|
+
* Card data can now include tags for importing into Anki.
|
5
|
+
|
3
6
|
## 0.0.1 (April 8, 2014 - Initial release!)
|
4
7
|
* Basic importing of an array of hashes into a string that can be used to create files to import to Anki (plain text only).
|
5
8
|
* Optionally saving string directly to a file, ready to be imported into Anki.
|
data/README.md
CHANGED
@@ -18,9 +18,9 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Generating a string for cards
|
22
22
|
|
23
|
-
|
23
|
+
After requiring the anki gem, simply create a new instance of `Anki::Deck`, pass in an array of hashes (either including the `card_data` option when creating the `Anki::Deck` object, or using the `Anki::Deck#card_data` method), and generate the deck by using the `Anki::Deck#generate_deck` method. It will return a string that is formatted to be ready to be saved into a file for importing into Anki.
|
24
24
|
|
25
25
|
```ruby
|
26
26
|
require 'anki'
|
@@ -38,12 +38,42 @@ deck.card_data = cards
|
|
38
38
|
|
39
39
|
deck.generate_deck
|
40
40
|
# => "Front of the card;Back of the card\nAnother card;Another answer"
|
41
|
+
```
|
42
|
+
|
43
|
+
### Generating a file
|
44
|
+
|
45
|
+
Alternatively, you can pass an optional `file` option when generating the deck to save the string into a file directly.
|
41
46
|
|
47
|
+
```ruby
|
48
|
+
require 'anki'
|
49
|
+
|
50
|
+
cards = [
|
51
|
+
{ "Front of the card" => "Back of the card" },
|
52
|
+
{ "Another card" => "Another answer" }
|
53
|
+
]
|
54
|
+
|
55
|
+
deck = Anki::Deck.new(card_data: cards)
|
42
56
|
# If you want to save it into a file directly, you can pass an optional `file` option
|
43
57
|
# with the path where you want to save the file:
|
44
58
|
deck.generate_deck(file: "/tmp/anki_deck.txt")
|
45
59
|
```
|
46
60
|
|
61
|
+
### Including card tags
|
62
|
+
|
63
|
+
If you want to include tags with the generated Anki deck, the value of the card data can be a hash that includes an array of strings.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require 'anki'
|
67
|
+
|
68
|
+
card = [
|
69
|
+
{ "Front" => { "value" => "Back", "tags" => ["tag1, tag2"]} }
|
70
|
+
]
|
71
|
+
|
72
|
+
deck = Anki::Deck.new(card_data: card)
|
73
|
+
deck.generate_deck
|
74
|
+
# => "Front;Back;tag1 tag2"
|
75
|
+
```
|
76
|
+
|
47
77
|
## Contributing
|
48
78
|
|
49
79
|
1. Fork the anki gem into your own repo (https://github.com/dennmart/anki/fork)
|
data/anki.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
22
21
|
spec.add_development_dependency "rake"
|
23
22
|
spec.add_development_dependency "rspec", "~> 2.14"
|
24
23
|
spec.add_development_dependency "fakefs", "~> 0.5"
|
data/lib/anki/deck.rb
CHANGED
@@ -11,13 +11,26 @@ module Anki
|
|
11
11
|
raise ArgumentError, "card_data should be an array of hashes" if !self.card_data.is_a?(Array)
|
12
12
|
raise ArgumentError, "You need card data." if self.card_data.empty?
|
13
13
|
|
14
|
-
anki_string = self.card_data.map { |card|
|
14
|
+
anki_string = self.card_data.map { |card| card_data_to_string(card) }.compact.join("\n")
|
15
15
|
create_file(anki_string, options[:file]) if options[:file]
|
16
16
|
anki_string
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
+
def card_data_to_string(card)
|
22
|
+
front_card = card.keys.first
|
23
|
+
back_card = card.values.first
|
24
|
+
|
25
|
+
if back_card.is_a?(String)
|
26
|
+
"#{front_card};#{back_card}"
|
27
|
+
elsif back_card.is_a?(Hash)
|
28
|
+
back_card_value = back_card["value"]
|
29
|
+
tags = back_card["tags"].join(" ")
|
30
|
+
"#{front_card};#{back_card_value};#{tags}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
def create_file(str, file)
|
22
35
|
File.open(file, 'w') { |f| f.write(str) }
|
23
36
|
end
|
data/lib/anki/version.rb
CHANGED
data/spec/anki/deck_spec.rb
CHANGED
@@ -31,5 +31,13 @@ describe Anki::Deck do
|
|
31
31
|
subject.generate_deck(file: "/tmp/anki_deck.txt")
|
32
32
|
File.exists?("/tmp/anki_deck.txt").should be_true
|
33
33
|
end
|
34
|
+
|
35
|
+
it "returns a string including tags if the value of each card data is a hash" do
|
36
|
+
subject.card_data = [{ "a" => { "value" => "b", "tags" => ["level1"] } },
|
37
|
+
{ "c" => { "value" => "d", "tags" => ["level1", "level2"] } }]
|
38
|
+
|
39
|
+
subject.generate_deck.should match /a;b;level1/
|
40
|
+
subject.generate_deck.should match /c;d;level1 level2/
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Martinez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.6'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +63,7 @@ extra_rdoc_files: []
|
|
77
63
|
files:
|
78
64
|
- ".gitignore"
|
79
65
|
- ".rspec"
|
66
|
+
- ".travis.yml"
|
80
67
|
- CHANGELOG.md
|
81
68
|
- Gemfile
|
82
69
|
- LICENSE.txt
|