anki 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/anki.gemspec +25 -0
- data/lib/anki.rb +2 -0
- data/lib/anki/deck.rb +25 -0
- data/lib/anki/version.rb +3 -0
- data/spec/anki/deck_spec.rb +35 -0
- data/spec/spec_helper.rb +8 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1821356b088ea19655b5ac0d3365a754053c6a4
|
4
|
+
data.tar.gz: 43d256ce60dd223d14608147b64c1f3b62f96584
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbc2ba00f45a777cca7561e73224fcbf2dd1c7c148bf16625f47bd56b0c17ec790f95ad2f0743a976dd03ef2e47db46153fb81991ecca39ec67174de4fc70bb6
|
7
|
+
data.tar.gz: cc2243b6267c3c569645508f48f539803ceecc815c588627e2560120ade04c000589c695dfd4c63f0953220d35a3819b069542859c82250c27620e0df0898f27
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dennis Martinez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Anki
|
2
|
+
|
3
|
+
Generate decks ready to be imported into [Anki](http://ankisrs.net/)! The anki gem will take an array of hashes and convert them into a string which can then be saved to a file that is ready to be imported into your Anki decks.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'anki'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install anki
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
23
|
+
Alternatively, you can pass an optional `file` option when generating the deck to save the string into a file directly.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'anki'
|
27
|
+
|
28
|
+
cards = [
|
29
|
+
{ "Front of the card" => "Back of the card" },
|
30
|
+
{ "Another card" => "Another answer" }
|
31
|
+
]
|
32
|
+
|
33
|
+
deck = Anki::Deck.new(card_data: cards)
|
34
|
+
|
35
|
+
# Alternatively, you can pass in the array of hashes for card data
|
36
|
+
# after initializing the object:
|
37
|
+
deck.card_data = cards
|
38
|
+
|
39
|
+
deck.generate_deck
|
40
|
+
# => "Front of the card;Back of the card\nAnother card;Another answer"
|
41
|
+
|
42
|
+
# If you want to save it into a file directly, you can pass an optional `file` option
|
43
|
+
# with the path where you want to save the file:
|
44
|
+
deck.generate_deck(file: "/tmp/anki_deck.txt")
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork the anki gem into your own repo (https://github.com/dennmart/anki/fork)
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`) and make sure your write tests for your new feature!
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
54
|
+
6. That's it! High fives given upon request :)
|
data/Rakefile
ADDED
data/anki.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'anki/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "anki"
|
8
|
+
spec.version = Anki::VERSION
|
9
|
+
spec.authors = ["Dennis Martinez"]
|
10
|
+
spec.email = ["dennis@dennmart.com"]
|
11
|
+
spec.summary = "Generate decks ready to be imported into Anki!"
|
12
|
+
spec.description = "Generate decks ready to be imported into Anki! Just pass an array of hashes and get back a string that you can save in a file and import directly into Anki."
|
13
|
+
spec.homepage = "https://github.com/dennmart/anki"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
spec.add_development_dependency "fakefs", "~> 0.5"
|
25
|
+
end
|
data/lib/anki.rb
ADDED
data/lib/anki/deck.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Anki
|
3
|
+
class Deck
|
4
|
+
attr_accessor :card_data
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@card_data = options.delete(:card_data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_deck(options = {})
|
11
|
+
raise ArgumentError, "card_data should be an array of hashes" if !self.card_data.is_a?(Array)
|
12
|
+
raise ArgumentError, "You need card data." if self.card_data.empty?
|
13
|
+
|
14
|
+
anki_string = self.card_data.map { |card| "#{card.keys.first};#{card.values.first}" }.compact.join("\n")
|
15
|
+
create_file(anki_string, options[:file]) if options[:file]
|
16
|
+
anki_string
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def create_file(str, file)
|
22
|
+
File.open(file, 'w') { |f| f.write(str) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/anki/version.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Anki::Deck do
|
4
|
+
describe "#generate_deck" do
|
5
|
+
subject { Anki::Deck.new }
|
6
|
+
let(:cards) { [{ "a" => "b" }, { "c" => "d" }] }
|
7
|
+
|
8
|
+
it "raises an ArgumentError if card_data is not an array" do
|
9
|
+
subject.card_data = "I'm card_data!"
|
10
|
+
|
11
|
+
expect {
|
12
|
+
subject.generate_deck
|
13
|
+
}.to raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises an ArgumentError if card_data is an empty array" do
|
17
|
+
subject.card_data = []
|
18
|
+
|
19
|
+
expect {
|
20
|
+
subject.generate_deck
|
21
|
+
}.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns a string with the card_data hashes, separating key and value with a semicolon and adding line breaks" do
|
25
|
+
subject.card_data = cards
|
26
|
+
subject.generate_deck.should == "a;b\nc;d"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "saves to a file if the file option is passed" do
|
30
|
+
subject.card_data = cards
|
31
|
+
subject.generate_deck(file: "/tmp/anki_deck.txt")
|
32
|
+
File.exists?("/tmp/anki_deck.txt").should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Martinez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakefs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
description: Generate decks ready to be imported into Anki! Just pass an array of
|
70
|
+
hashes and get back a string that you can save in a file and import directly into
|
71
|
+
Anki.
|
72
|
+
email:
|
73
|
+
- dennis@dennmart.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- anki.gemspec
|
86
|
+
- lib/anki.rb
|
87
|
+
- lib/anki/deck.rb
|
88
|
+
- lib/anki/version.rb
|
89
|
+
- spec/anki/deck_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/dennmart/anki
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Generate decks ready to be imported into Anki!
|
115
|
+
test_files:
|
116
|
+
- spec/anki/deck_spec.rb
|
117
|
+
- spec/spec_helper.rb
|