ank3 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7264b15ab44ed69dddccfe928e26595b2769b855987ed9190fed2274a7a8da37
4
- data.tar.gz: 2811385ba9476ca20a574e52f9bfebc8d0ef6695b9b16a6ac84a1db53a32967f
3
+ metadata.gz: ba67428ad2764e669fc40069a5ca14aa90b5d25717546074d5fd87ea86c9b63e
4
+ data.tar.gz: 4eb033d5c51fde87071848be058d73fda15717876b6f05b6425e498629a5f32c
5
5
  SHA512:
6
- metadata.gz: d27f79862af764610b4edeedea1c6c1f6e099c83579bd3eaf15ad658303821a24fc81d54315e0e908475c90a0e47de7f6b45b55a4a48d843aff7c419d0e9cc68
7
- data.tar.gz: 043b74edfa4bb40438546ce82eb7dd52cc728c9ef3bed44dc4c9f8fedfc4fc08e17aa3db1c7044f68dd1fb51ff6e97c3f335d1bddc4f200778c69b5ede98764e
6
+ metadata.gz: 122e6ca454cf798551dfc8a0d9b27ebff2c69e53799e9760c9d79ef27e5d70204750308602b3c0aef30584d37b47f0ff032060bf7e207ba12f9924332af3f472
7
+ data.tar.gz: d035c2aebc1be263a7b207439497884e72ac1f81c2f091b8fc6162f219f3e2108d1a76081d10d3231cdfb502da5a7dae42a4100bb9f81d6840eab9264ecdb2a9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ank3 (0.1.0)
4
+ ank3 (0.2.0)
5
5
  thor
6
6
 
7
7
  GEM
@@ -13,7 +13,7 @@ GEM
13
13
  pry (0.12.2)
14
14
  coderay (~> 1.1.0)
15
15
  method_source (~> 0.9.0)
16
- rake (10.5.0)
16
+ rake (13.0.1)
17
17
  rspec (3.8.0)
18
18
  rspec-core (~> 3.8.0)
19
19
  rspec-expectations (~> 3.8.0)
@@ -36,7 +36,7 @@ DEPENDENCIES
36
36
  ank3!
37
37
  bundler (~> 2.0)
38
38
  pry
39
- rake (~> 10.0)
39
+ rake (~> 13.0)
40
40
  rspec (~> 3.0)
41
41
 
42
42
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # Ank3
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ank3`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Ank3 is a simple command line interface (CLI) to create text files that can be ingested by Anki to create Anki cards.
4
+ Alternatively, you can generate a boilerplate YAML file where you can create cards with a front, back, and tags.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ ## Motivation and Anki work flow
7
+
8
+ I personally use Anki to review anything that I study. I don't always have the app available
9
+ nor do I want to always use the app to create new cards. Sometimes I want to review the questions/answers
10
+ of the cards because I actually create them, so I put them in a separate text file where I copy and paste
11
+ to questions and answers to Anki when I'm ready to create the cards. This procedure is too manual, so I
12
+ thought I would try to automate it by creating this gem.
13
+
14
+ You might ask why not just create the simple Anki text file?
15
+ The reason is because I would like to use the YAML files for other purposes, such
16
+ as storing or parsing it as notes.
6
17
 
7
18
  ## Installation
8
19
 
@@ -22,11 +33,56 @@ Or install it yourself as:
22
33
 
23
34
  ## Usage
24
35
 
25
- TODO: Write usage instructions here
36
+ To parse a YAML file to a Anki .txt file, simply run:
37
+
38
+ ```./ank3 covert [FILE.yml]``` in the command line.
39
+
40
+ Example:
41
+
42
+ Using a YAML file that looks like:
43
+
44
+ ```yaml
45
+ ---
46
+ - front: 'What is 1+1?'
47
+ back: 'Two'
48
+ tags: []
49
+ ---
50
+ - front: 'What is H20?'
51
+ back: 'Water'
52
+ tags: []
53
+ ```
54
+
55
+ will generate a .txt file that looks like:
56
+
57
+ ```
58
+ What is 1+1?; Two
59
+ What is H2O?; Water
60
+ ```
61
+
62
+ To generate a boilerplate file, simply run:
63
+
64
+ ```./ank3 generate_boilerplate [number of cards]``` and it will generate a YAML file containing an array with [number of cards] of hashes.
65
+
66
+ For example:
67
+
68
+ ```./ank3 generate_boilerplate 3``` will generate a YAML file with 3 hashes, each representing a card looking like this:
69
+
70
+ ```yaml
71
+ ---
72
+ - front: ''
73
+ back: ''
74
+ tags: []
75
+ - front: ''
76
+ back: ''
77
+ tags: []
78
+ - front: ''
79
+ back: ''
80
+ tags: []
81
+ ```
26
82
 
27
83
  ## Development
28
84
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
30
86
 
31
87
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
88
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_runtime_dependency "thor"
32
32
  spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
  spec.add_development_dependency "pry"
36
36
  end
data/bin/ank3 CHANGED
@@ -2,14 +2,5 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "ank3"
5
- # You can add fixtures and/or initialization code here to make experimenting
6
- # with your gem easier. You can also use a different console, if you like.
7
-
8
- # (If you use this, don't forget to add pry to your Gemfile!)
9
- # require "pry"
10
- # Pry.start
11
-
12
- # require "irb"
13
- # IRB.start(__FILE__)
14
5
 
15
6
  Ank3::Cli.start(ARGV)
@@ -6,8 +6,8 @@ module Ank3
6
6
  end
7
7
 
8
8
  desc "generate_boilerplate", "Generate a boilerplate YAML file"
9
- def generate_boilerplate(number = 1, file_name = "ank3.yml")
10
- Ank3::Collection.generate_boilerplate_file(number, file_name)
9
+ def generate_boilerplate(file_name = "ank3.yml", number = 1)
10
+ Ank3::Collection.generate_boilerplate_file(file_name, number)
11
11
  end
12
12
  end
13
13
  end
@@ -1,8 +1,9 @@
1
1
  module Ank3
2
2
  class Collection
3
- attr_reader :cards, :data
3
+ attr_reader :cards, :data, :basename
4
4
 
5
5
  def initialize(file)
6
+ @basename = File.basename(file, ".yml")
6
7
  @data = YAML.load(File.read(file))
7
8
  @cards = []
8
9
  convert_data_to_cards
@@ -16,14 +17,15 @@ module Ank3
16
17
  @cards.map { |card| card.convert if front_and_back_present?(card) }.join("")
17
18
  end
18
19
 
19
- def write_to_file(name = "cards")
20
- File.open("#{name}.txt", "w") do |file|
20
+ def write_to_file(name = "")
21
+ file_name = name != "" ? name : @basename
22
+ File.open("#{file_name}.txt", "w") do |file|
21
23
  file.write(convert)
22
24
  file
23
25
  end
24
26
  end
25
27
 
26
- def self.generate_boilerplate_file(number = 1, file_name = "ank3.yml")
28
+ def self.generate_boilerplate_file(file_name = "ank3.yml", number = 1)
27
29
  array_of_hashes = []
28
30
  number.to_i.times do
29
31
  array_of_hashes << {
@@ -36,6 +38,11 @@ module Ank3
36
38
  file.write(array_of_hashes.to_yaml)
37
39
  file
38
40
  end
41
+ new_file = convert_yaml_to_double_quotes!(file_name)
42
+ File.open(file_name, "w") do |file|
43
+ file.write(new_file)
44
+ file
45
+ end
39
46
  end
40
47
 
41
48
  private
@@ -49,5 +56,10 @@ module Ank3
49
56
  def front_and_back_present?(card)
50
57
  !card.front.empty? && !card.back.empty?
51
58
  end
59
+
60
+ def self.convert_yaml_to_double_quotes!(file)
61
+ # https://stackoverflow.com/questions/18316333/how-do-i-force-double-quotes-when-dumping-yaml
62
+ File.read(file).gsub("'", "\"")
63
+ end
52
64
  end
53
65
  end
@@ -1,3 +1,3 @@
1
1
  module Ank3
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ank3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hobertro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-18 00:00:00.000000000 Z
11
+ date: 2020-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,7 +87,6 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".DS_Store"
91
90
  - ".gitignore"
92
91
  - ".rspec"
93
92
  - ".travis.yml"
data/.DS_Store DELETED
Binary file