lexdrill 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 +4 -4
- data/README.md +28 -4
- data/lexdrill.gemspec +3 -3
- data/lib/lexdrill/cli.rb +16 -2
- data/lib/lexdrill/config.rb +18 -0
- data/lib/lexdrill/counter.rb +33 -0
- data/lib/lexdrill/version.rb +1 -1
- data/lib/lexdrill/word_list.rb +26 -0
- data/lib/lexdrill.rb +3 -0
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ee9e8bd1de6b7fc437375184394a0ce42d61d9648320e6a31e83bf575cfc885
|
|
4
|
+
data.tar.gz: 27836a51638dbd08eb53a1d6f6808d94a0fb27c8e4b93cd831e96c2f5b0abe64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb860ea6fb40050205abbbdc2078d1a3e5b4f624629bb1b769a33c7bd1de3e22452d65265017cd0e7597bde5d934b04c568e96ab8f2643678392dfe86a8e2dc6
|
|
7
|
+
data.tar.gz: edbe4b9f27ced36534b9f3816840feb9216728288077af785292b12015d765db0c96170a0f8f79dc9182926323b3404517abd237ff51b47747901fb4e93632a7
|
data/README.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# lexdrill
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
lexdrill prints a vocabulary word or phrase on demand, tracking how often each one has been shown.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install lexdrill
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### `lexdrill: command not found` after install?
|
|
12
|
+
|
|
13
|
+
This happens when the gem's executable directory isn't on your `PATH` — common with a
|
|
14
|
+
plain system Ruby (no rbenv/rvm). Fix it in one step:
|
|
15
|
+
|
|
16
|
+
**bash**
|
|
17
|
+
```bash
|
|
18
|
+
echo "export PATH=\"$(ruby -e 'puts Gem.bindir'):\$PATH\"" >> ~/.bashrc
|
|
19
|
+
source ~/.bashrc
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**zsh**
|
|
23
|
+
```zsh
|
|
24
|
+
echo "export PATH=\"$(ruby -e 'puts Gem.bindir'):\$PATH\"" >> ~/.zshrc
|
|
25
|
+
source ~/.zshrc
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Using an rbenv-managed Ruby? Run `rbenv rehash` instead. Using rvm? You shouldn't hit
|
|
29
|
+
this — rvm keeps gem executable directories on `PATH` automatically.
|
data/lexdrill.gemspec
CHANGED
|
@@ -6,18 +6,18 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.name = "lexdrill"
|
|
7
7
|
spec.version = Lexdrill::VERSION
|
|
8
8
|
spec.authors = ["Siarhei Kisliak"]
|
|
9
|
-
spec.email = ["
|
|
9
|
+
spec.email = ["kislak7@gmail.com"]
|
|
10
10
|
|
|
11
11
|
spec.summary = "Vocabulary drilling in your terminal."
|
|
12
12
|
spec.description = "lexdrill prints a vocabulary word or phrase on demand, tracking how often " \
|
|
13
13
|
"each one has been shown."
|
|
14
|
-
spec.homepage = "https://github.com/
|
|
14
|
+
spec.homepage = "https://github.com/kislak/lexdrill"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
spec.required_ruby_version = ">= 3.0"
|
|
17
17
|
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
20
|
-
spec.metadata["rubygems_mfa_required"] = "
|
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
21
21
|
|
|
22
22
|
spec.files = Dir.chdir(__dir__) do
|
|
23
23
|
Dir["lib/**/*.rb"] + Dir["bin/*"] + %w[README.md LICENSE.txt lexdrill.gemspec Gemfile]
|
data/lib/lexdrill/cli.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Subcommand dispatcher for the `lexdrill` executable.
|
|
4
3
|
class Lexdrill::CLI
|
|
5
4
|
COMMANDS = {
|
|
6
5
|
print_version: %w[version --version -v],
|
|
7
|
-
print_help: %w[help --help -h]
|
|
6
|
+
print_help: %w[help --help -h],
|
|
7
|
+
run_next: %w[next]
|
|
8
8
|
}.freeze
|
|
9
9
|
|
|
10
10
|
def self.start(argv = ARGV)
|
|
@@ -39,10 +39,24 @@ class Lexdrill::CLI
|
|
|
39
39
|
Usage:
|
|
40
40
|
lexdrill version Print the gem version
|
|
41
41
|
lexdrill help Show this help
|
|
42
|
+
lexdrill next Print the current word and advance
|
|
42
43
|
HELP
|
|
43
44
|
0
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
def run_next
|
|
48
|
+
word = Lexdrill::WordList.next
|
|
49
|
+
return print_no_words(Lexdrill::WordList::PATH) unless word
|
|
50
|
+
|
|
51
|
+
puts word
|
|
52
|
+
0
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def print_no_words(path)
|
|
56
|
+
warn "lexdrill: no words found in #{path}"
|
|
57
|
+
1
|
|
58
|
+
end
|
|
59
|
+
|
|
46
60
|
def print_unknown_command(command)
|
|
47
61
|
warn "lexdrill: unknown command #{command.inspect}"
|
|
48
62
|
print_help
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lexdrill::Config
|
|
4
|
+
FILENAME = ".drill.txt"
|
|
5
|
+
COUNTER_FILENAME = ".drill.counter"
|
|
6
|
+
|
|
7
|
+
def self.dir_path
|
|
8
|
+
cwd = Dir.pwd
|
|
9
|
+
cwd if File.exist?(File.join(cwd, FILENAME))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.base_path
|
|
13
|
+
ENV.fetch("LEXDRILL_PATH", nil) || dir_path || Dir.home
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
DRILL_PATH = File.join(base_path, FILENAME)
|
|
17
|
+
COUNTER_PATH = File.join(base_path, COUNTER_FILENAME)
|
|
18
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Lexdrill::Counter
|
|
4
|
+
attr_reader :path
|
|
5
|
+
|
|
6
|
+
def initialize(path)
|
|
7
|
+
@path = path
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def value
|
|
11
|
+
return 0 unless File.exist?(path)
|
|
12
|
+
|
|
13
|
+
File.read(path).strip.to_i
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def increment
|
|
17
|
+
File.write(path, (value + 1).to_s)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def reset
|
|
21
|
+
File.write(path, "0")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The current value, unless it's out of bounds for the given size, in
|
|
25
|
+
# which case it resets to 0 first.
|
|
26
|
+
def bounded_value(size)
|
|
27
|
+
current = value
|
|
28
|
+
return current if current < size
|
|
29
|
+
|
|
30
|
+
reset
|
|
31
|
+
0
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/lexdrill/version.rb
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Reads vocabulary words/phrases from a `.drill.txt` file, one per line, and
|
|
4
|
+
# advances a persisted counter to show "the current word" each time.
|
|
5
|
+
class Lexdrill::WordList
|
|
6
|
+
PATH = Lexdrill::Config::DRILL_PATH
|
|
7
|
+
COUNTER_PATH = Lexdrill::Config::COUNTER_PATH
|
|
8
|
+
|
|
9
|
+
def self.words
|
|
10
|
+
@words ||= File.exist?(PATH) && File.readlines(PATH).map(&:strip).reject(&:empty?)
|
|
11
|
+
@words ||= []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.next
|
|
15
|
+
return nil if words.empty?
|
|
16
|
+
|
|
17
|
+
words[take_index(words.size)]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.take_index(size)
|
|
21
|
+
counter = Lexdrill::Counter.new(COUNTER_PATH)
|
|
22
|
+
index = counter.bounded_value(size)
|
|
23
|
+
counter.increment
|
|
24
|
+
index
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/lexdrill.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lexdrill
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Siarhei Kisliak
|
|
@@ -13,7 +13,7 @@ dependencies: []
|
|
|
13
13
|
description: lexdrill prints a vocabulary word or phrase on demand, tracking how often
|
|
14
14
|
each one has been shown.
|
|
15
15
|
email:
|
|
16
|
-
-
|
|
16
|
+
- kislak7@gmail.com
|
|
17
17
|
executables:
|
|
18
18
|
- lexdrill
|
|
19
19
|
extensions: []
|
|
@@ -26,14 +26,17 @@ files:
|
|
|
26
26
|
- lexdrill.gemspec
|
|
27
27
|
- lib/lexdrill.rb
|
|
28
28
|
- lib/lexdrill/cli.rb
|
|
29
|
+
- lib/lexdrill/config.rb
|
|
30
|
+
- lib/lexdrill/counter.rb
|
|
29
31
|
- lib/lexdrill/version.rb
|
|
30
|
-
|
|
32
|
+
- lib/lexdrill/word_list.rb
|
|
33
|
+
homepage: https://github.com/kislak/lexdrill
|
|
31
34
|
licenses:
|
|
32
35
|
- MIT
|
|
33
36
|
metadata:
|
|
34
|
-
homepage_uri: https://github.com/
|
|
35
|
-
source_code_uri: https://github.com/
|
|
36
|
-
rubygems_mfa_required: '
|
|
37
|
+
homepage_uri: https://github.com/kislak/lexdrill
|
|
38
|
+
source_code_uri: https://github.com/kislak/lexdrill
|
|
39
|
+
rubygems_mfa_required: 'true'
|
|
37
40
|
post_install_message:
|
|
38
41
|
rdoc_options: []
|
|
39
42
|
require_paths:
|