kukushka 0.1.6 → 0.1.8

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: f8fc7f68739f9bdab5376289a7b2e96d71c1ff8eec6434713eda6449c8288d54
4
- data.tar.gz: 5412fb1373f59c6a6adb31e5b07d0cdb41e08cba8eaf719cf8182861634a5efe
3
+ metadata.gz: 92ab7d9dc8513ea956f2e2f4a0351fc568deeee3f372cc0d888b56e1eb8fb0f6
4
+ data.tar.gz: b2cae314f91fdbd8af055b6377632188e7591ceb7f8c5941c7d7201b7687c4bb
5
5
  SHA512:
6
- metadata.gz: 1d8067be85d430addabde2902b45a0092ae0c00faad9247d9c2291eb6032543dcbca65587419a887999a32a98bec8a0fc98bba2062ae65ba98d760130489e1ae
7
- data.tar.gz: 3ccd5e3fbe5ebe9e67aadb219854918175398a3fb0403841c3e9cb0d7e1b7d2b740a0c8b849060740dd19ec6ace50012b41be042a82630a38e92b76ffe22fbb1
6
+ metadata.gz: ab7efa3e67b77a343a702d0adcfab9449bfc4ed8823f0e1f9883b22ea11e78266bfb15e0a683e8ce2873ba72a78328ee4ff5efe1f3fc2a0b61889376cdb94877
7
+ data.tar.gz: 6a2fd3c7fce07d40a054ad89b0e9a9ed17390d028110ecb2f85cf0224d6206d362de8acf05822aa206eff0556123ce84a77bfe6601283b2fe3179cf40342fb59
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ kukushka
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.4
data/Gemfile.lock CHANGED
@@ -1,8 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kukushka (0.1.6)
4
+ kukushka (0.1.8)
5
+ commander (~> 4.4)
5
6
  rainbow (~> 3.0)
7
+ redis (~> 5.3)
8
+ redis-namespace (~> 1.11)
6
9
 
7
10
  GEM
8
11
  remote: https://rubygems.org/
@@ -10,7 +13,10 @@ GEM
10
13
  ast (2.4.2)
11
14
  bigdecimal (3.1.8)
12
15
  coderay (1.1.3)
16
+ commander (4.6.0)
17
+ highline (~> 2.0.0)
13
18
  concurrent-ruby (1.3.4)
19
+ connection_pool (2.4.1)
14
20
  diff-lcs (1.5.1)
15
21
  dry-configurable (1.2.0)
16
22
  dry-core (~> 1.0, < 2)
@@ -40,6 +46,7 @@ GEM
40
46
  dry-inflector (~> 1.0)
41
47
  dry-logic (~> 1.4)
42
48
  zeitwerk (~> 2.6)
49
+ highline (2.0.3)
43
50
  json (2.9.0)
44
51
  language_server-protocol (3.17.0.3)
45
52
  logger (1.6.3)
@@ -54,6 +61,12 @@ GEM
54
61
  racc (1.8.1)
55
62
  rainbow (3.1.1)
56
63
  rake (13.2.1)
64
+ redis (5.3.0)
65
+ redis-client (>= 0.22.0)
66
+ redis-client (0.23.0)
67
+ connection_pool
68
+ redis-namespace (1.11.0)
69
+ redis (>= 4)
57
70
  reek (6.3.0)
58
71
  dry-schema (~> 1.13.0)
59
72
  parser (~> 3.3.0)
data/README.md CHANGED
@@ -45,4 +45,13 @@ bundle init
45
45
 
46
46
  gem 'pry'
47
47
  gem 'kukushka', path: '/Users/Siarhei/laboratory/kukushka'
48
- ```
48
+ ```
49
+
50
+ ```bash
51
+ gem build kukushka.gemspec
52
+ gem push kukushka-0.x.y.gem
53
+ ```
54
+
55
+ dependencies
56
+ https://github.com/redis/redis-rb
57
+ https://github.com/commander-rb/commander
data/exe/kuku CHANGED
@@ -2,12 +2,63 @@
2
2
  require 'yaml'
3
3
  require 'kukushka'
4
4
  require 'pry'
5
+ require 'commander'
6
+ require 'redis'
7
+ require 'redis-namespace'
8
+ require 'json'
5
9
 
6
- if ARGV.join('') == 'on'
7
- Kukushka.on!
8
- end
9
10
 
10
- return unless Kukushka.on?
11
+ redis_connection = Redis.new
12
+ redis = Redis::Namespace.new(:kukushka, redis: redis_connection)
13
+
14
+ Commander.configure do
15
+ program :name, 'kuku'
16
+ program :version, '1.0.0'
17
+ program :description, 'learn list'
18
+ default_command :sample
19
+
20
+ command :sample do |c|
21
+ c.syntax = 'kuku sample'
22
+ c.description = 'Show next sample'
23
+ c.action do |args, options|
24
+ next unless redis.get('enabled') == 'true'
25
+
26
+ res = Kukushka.kuku(redis)
27
+ puts res if res
28
+ end
29
+ end
11
30
 
12
- res = Kukushka.kuku(ARGV)
13
- puts res if res
31
+ command :init do |c|
32
+ c.syntax = 'kuku init'
33
+ c.description = 'Default initiation'
34
+ c.action do |args, options|
35
+ # res = Kukushka.kuku(ARGV)
36
+ # puts res if res
37
+ end
38
+ end
39
+
40
+ command :source do |c|
41
+ c.syntax = 'kuku source file_path'
42
+ c.description = 'Add new source'
43
+ c.action do |args, options|
44
+ lines = File.readlines(args.first, chomp: true)
45
+ redis.set(:lines, lines.to_json)
46
+ end
47
+ end
48
+
49
+ command :on do |c|
50
+ c.syntax = 'kuku on'
51
+ c.description = 'Disable'
52
+ c.action do |args, options|
53
+ redis.set('enabled', true)
54
+ end
55
+ end
56
+
57
+ command :off do |c|
58
+ c.syntax = 'kuku off'
59
+ c.description = 'disable'
60
+ c.action do |args, options|
61
+ redis.set('enabled', false)
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/kukushka.rb CHANGED
@@ -5,147 +5,26 @@ require 'rainbow'
5
5
  require 'yaml'
6
6
 
7
7
  module Kukushka
8
- INIT_CTA = "TODO: kuku init source_file"
9
- PROVIDE_SOURCE_CTA = "TODO: provide valid source_file path"
10
- DEFAULT_CIRCLE = 5
8
+ EXAMPLE_SOURCE ||= File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
9
+ DEFULAT_LINES = File.readlines(EXAMPLE_SOURCE, chomp: true)
11
10
 
12
- def self.kuku(args)
13
- Kukushka.kuku(args)
14
- end
15
-
16
- def self.on?
17
- Config.new.on?
18
- end
19
-
20
- def self.on!
21
- Config.new.enable
22
- end
23
-
24
- class Config
25
- CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
26
- CONFIG_DIR = File.dirname(CONFIG_FILE)
27
-
28
- def on?
29
- return true unless exists?
30
- exists? && config[:enabled]
31
- end
32
-
33
- def exists?
34
- File.exists?(CONFIG_DIR)
35
- end
36
-
37
- def init(source_file)
38
- source_file ||= File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
39
- return INIT_CTA if source_file.nil?
40
- return PROVIDE_SOURCE_CTA unless File.exist?(source_file)
41
-
42
- dir = File.dirname(CONFIG_FILE)
43
- FileUtils.mkdir_p(dir) unless File.exists?(dir)
44
- config = {
45
- source: source_file,
46
- enabled: true,
47
- counter: 0,
48
- from: 0,
49
- circle: DEFAULT_CIRCLE,
50
- }
51
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
52
- end
53
-
54
- def enable
55
- config.merge!(enabled: true)
56
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
57
- 'enabled'
58
- end
59
-
60
- def disable
61
- config.merge!(enabled: false)
62
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
63
- 'disabled'
64
- end
65
-
66
- def cleanup
67
- FileUtils.rm_rf(CONFIG_DIR) if config_exists?
68
- end
69
-
70
- def source
71
- @source ||= config[:source]
72
- end
73
-
74
- def counter
75
- @counter ||= config[:counter]
76
- end
77
-
78
- def from
79
- @from ||= config[:from]
80
- end
81
-
82
- def circle
83
- @circle ||= config[:circle]
84
- end
85
-
86
- def set_counter(new_counter)
87
- config.merge!(counter: new_counter)
88
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
89
- end
90
-
91
- def set_circle(new_circle)
92
- config.merge!(circle: new_circle)
93
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
94
- end
95
-
96
- def set_from(new_from)
97
- config.merge!(from: new_from)
98
- File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
99
- end
100
-
101
- def config
102
- @config ||= YAML::load_file(CONFIG_FILE)
103
- end
11
+ def self.kuku(redis)
12
+ Kukushka.kuku(redis)
104
13
  end
105
14
 
106
15
  class Kukushka
107
- def self.kuku(args)
108
- new(args).kuku
16
+ def self.kuku(redis)
17
+ new(redis).kuku
109
18
  end
110
19
 
111
- def initialize(args)
112
- @command = args[0]
113
- @param1 = args[1]
114
- @config = Config.new
20
+ def initialize(redis)
21
+ @redis = redis
115
22
  end
116
23
 
117
- attr_reader :command, :param1, :config
24
+ attr_reader :redis
118
25
 
119
26
  def kuku
120
- config.init(param1) if command == 'init'
121
-
122
- return INIT_CTA unless config.exists?
123
-
124
- return config.enable if command == 'on'
125
- return config.disable if command == 'off'
126
-
127
- if command == 'counter'
128
- return config.set_counter(0) if param1.nil?
129
- return config.set_counter(nil) if param1 == 'no' || param1 == 'off' || param1 == 'nil'
130
- return config.set_counter(param1.to_i)
131
- end
132
-
133
- if command == 'from'
134
- config.set_from(0) if param1.nil?
135
- config.set_from(param1.to_i)
136
- config.set_counter(config.from)
137
- end
138
-
139
- if command == 'circle'
140
- config.set_circle(DEFAULT_CIRCLE) if param1.nil?
141
- config.set_circle(param1.to_i)
142
- config.set_counter(config.from)
143
- end
144
-
145
- return config.cleanup if command == 'cleanup'
146
- # return show if command == 'show'
147
- return sample if command == 'sample'
148
- return punchline
27
+ Rainbow(sample).color(color).bright
149
28
  end
150
29
 
151
30
  private
@@ -163,30 +42,54 @@ module Kukushka
163
42
  # end
164
43
 
165
44
  def sample
166
- if config.counter
167
- config.set_counter(config.counter + 1)
168
- config.set_counter(0) if config.counter > lines.size
45
+ if counter
46
+ set_counter(counter + 1)
47
+ set_counter(0) if counter > lines.size
169
48
 
170
- if config.counter < config.from
171
- config.set_counter(config.from)
49
+ if counter < from
50
+ set_counter(from)
172
51
  end
173
52
 
174
- if config.counter >= config.from + config.circle - 1
175
- config.set_counter(config.from)
53
+ if counter > to
54
+ set_counter(from)
176
55
  end
177
56
 
178
- return "#{lines[config.counter]} #{config.counter}/#{lines.size}"
57
+ return "#{lines[counter]} #{counter} [#{from}-#{to}/#{lines.size - 1}]"
179
58
  end
180
59
 
181
60
  lines.sample
182
61
  end
183
62
 
63
+ def counter
64
+ @counter ||= redis.get(:counter).to_i
65
+ end
66
+
67
+ def to
68
+ @to ||= from + circle - 1
69
+ end
70
+
71
+ def set_counter(new_counter)
72
+ redis.set(:counter, new_counter)
73
+ @counter = new_counter
74
+ end
75
+
184
76
  def lines
185
- @lines ||= File.readlines(config.source, chomp: true)
77
+ # binding.pry
78
+ redis_lines = redis.get(:lines)
79
+ if redis_lines
80
+ @lines = JSON.parse(redis.get(:lines))
81
+ end
82
+ @lines ||= DEFULAT_LINES
186
83
  end
187
84
 
188
- def punchline
189
- @punchline ||= Rainbow(sample).color(color).bright
85
+ def from
86
+ @from ||= redis.get(:from).to_i
87
+ end
88
+
89
+ def circle
90
+ @circle ||= redis.get(:circle).to_i
91
+ @circle = lines.size if @circle == 0
92
+ @circle
190
93
  end
191
94
 
192
95
  def color
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kukushka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
11
+ date: 2025-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis-namespace
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
27
69
  description: Learning tool for interval repetition
28
70
  email:
29
71
  - kislak7@gmail.com
@@ -34,14 +76,14 @@ extra_rdoc_files: []
34
76
  files:
35
77
  - ".rspec"
36
78
  - ".rubocop.yml"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
37
81
  - Gemfile
38
82
  - Gemfile.lock
39
83
  - LICENSE.txt
40
84
  - README.md
41
85
  - Rakefile
42
86
  - exe/kuku
43
- - kukushka-0.1.4.gem
44
- - kukushka-0.1.5.gem
45
87
  - lib/kukushka.rb
46
88
  - lib/kukushka/version.rb
47
89
  - sig/kukushka.rbs
@@ -64,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
106
  - !ruby/object:Gem::Version
65
107
  version: '0'
66
108
  requirements: []
67
- rubygems_version: 3.3.26
109
+ rubygems_version: 3.5.11
68
110
  signing_key:
69
111
  specification_version: 4
70
112
  summary: interval repetition
data/kukushka-0.1.4.gem DELETED
Binary file
data/kukushka-0.1.5.gem DELETED
Binary file