kukushka 0.1.4 → 0.1.6

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: 3888a46d589e195c57176e78f19727b7678022c470c739b724656e388efd70f3
4
- data.tar.gz: eb66d404b392cfdf36bf15be889e0c7b188f78bd062350fe645a5b52878d73a5
3
+ metadata.gz: f8fc7f68739f9bdab5376289a7b2e96d71c1ff8eec6434713eda6449c8288d54
4
+ data.tar.gz: 5412fb1373f59c6a6adb31e5b07d0cdb41e08cba8eaf719cf8182861634a5efe
5
5
  SHA512:
6
- metadata.gz: ec36e38cf546aeece6ada74fa685c2ac68cd4b1d08565eee7daff4f55a4d5183348d40212b473c28b22da774c19698593bf4a24392dad62d706ff2b56d23d686
7
- data.tar.gz: 796fcf9a585a6ad998b68ee01274db29f077f85784cc002fceed1d1e63a4d96960140cd54798b81365c4f015db4b0ac83068aa6f630eeb09e8c95c3fabc690fe
6
+ metadata.gz: 1d8067be85d430addabde2902b45a0092ae0c00faad9247d9c2291eb6032543dcbca65587419a887999a32a98bec8a0fc98bba2062ae65ba98d760130489e1ae
7
+ data.tar.gz: 3ccd5e3fbe5ebe9e67aadb219854918175398a3fb0403841c3e9cb0d7e1b7d2b740a0c8b849060740dd19ec6ace50012b41be042a82630a38e92b76ffe22fbb1
data/Gemfile.lock CHANGED
@@ -1,26 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kukushka (0.1.2)
4
+ kukushka (0.1.6)
5
5
  rainbow (~> 3.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ ast (2.4.2)
11
+ bigdecimal (3.1.8)
10
12
  coderay (1.1.3)
11
- diff-lcs (1.2.5)
13
+ concurrent-ruby (1.3.4)
14
+ diff-lcs (1.5.1)
15
+ dry-configurable (1.2.0)
16
+ dry-core (~> 1.0, < 2)
17
+ zeitwerk (~> 2.6)
18
+ dry-core (1.0.2)
19
+ concurrent-ruby (~> 1.0)
20
+ logger
21
+ zeitwerk (~> 2.6)
22
+ dry-inflector (1.1.0)
23
+ dry-initializer (3.1.1)
24
+ dry-logic (1.5.0)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-core (~> 1.0, < 2)
27
+ zeitwerk (~> 2.6)
28
+ dry-schema (1.13.4)
29
+ concurrent-ruby (~> 1.0)
30
+ dry-configurable (~> 1.0, >= 1.0.1)
31
+ dry-core (~> 1.0, < 2)
32
+ dry-initializer (~> 3.0)
33
+ dry-logic (>= 1.4, < 2)
34
+ dry-types (>= 1.7, < 2)
35
+ zeitwerk (~> 2.6)
36
+ dry-types (1.7.2)
37
+ bigdecimal (~> 3.0)
38
+ concurrent-ruby (~> 1.0)
39
+ dry-core (~> 1.0)
40
+ dry-inflector (~> 1.0)
41
+ dry-logic (~> 1.4)
42
+ zeitwerk (~> 2.6)
43
+ json (2.9.0)
44
+ language_server-protocol (3.17.0.3)
45
+ logger (1.6.3)
12
46
  method_source (1.1.0)
47
+ parallel (1.26.3)
48
+ parser (3.3.6.0)
49
+ ast (~> 2.4.1)
50
+ racc
13
51
  pry (0.15.0)
14
52
  coderay (~> 1.1)
15
53
  method_source (~> 1.0)
16
54
  racc (1.8.1)
17
55
  rainbow (3.1.1)
18
56
  rake (13.2.1)
19
- reek (1.3.7)
20
- rainbow
21
- ruby2ruby (~> 2.0.8)
22
- ruby_parser (~> 3.3)
23
- sexp_processor
57
+ reek (6.3.0)
58
+ dry-schema (~> 1.13.0)
59
+ parser (~> 3.3.0)
60
+ rainbow (>= 2.0, < 4.0)
61
+ rexml (~> 3.1)
62
+ regexp_parser (2.9.3)
63
+ rexml (3.3.9)
24
64
  rspec (3.13.0)
25
65
  rspec-core (~> 3.13.0)
26
66
  rspec-expectations (~> 3.13.0)
@@ -34,15 +74,23 @@ GEM
34
74
  diff-lcs (>= 1.2.0, < 2.0)
35
75
  rspec-support (~> 3.13.0)
36
76
  rspec-support (3.13.2)
37
- rubocop (0.7.2)
38
- rainbow (>= 1.1.4)
39
- ruby2ruby (2.0.8)
40
- ruby_parser (~> 3.1)
41
- sexp_processor (~> 4.0)
42
- ruby_parser (3.21.1)
43
- racc (~> 1.5)
44
- sexp_processor (~> 4.16)
45
- sexp_processor (4.17.3)
77
+ rubocop (1.69.2)
78
+ json (~> 2.3)
79
+ language_server-protocol (>= 3.17.0)
80
+ parallel (~> 1.10)
81
+ parser (>= 3.3.0.2)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ regexp_parser (>= 2.9.3, < 3.0)
84
+ rubocop-ast (>= 1.36.2, < 2.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (>= 2.4.0, < 4.0)
87
+ rubocop-ast (1.37.0)
88
+ parser (>= 3.3.1.0)
89
+ ruby-progressbar (1.13.0)
90
+ unicode-display_width (3.1.2)
91
+ unicode-emoji (~> 4.0, >= 4.0.4)
92
+ unicode-emoji (4.0.4)
93
+ zeitwerk (2.6.18)
46
94
 
47
95
  PLATFORMS
48
96
  arm64-darwin-22
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/kukushka.rb CHANGED
@@ -7,6 +7,7 @@ require 'yaml'
7
7
  module Kukushka
8
8
  INIT_CTA = "TODO: kuku init source_file"
9
9
  PROVIDE_SOURCE_CTA = "TODO: provide valid source_file path"
10
+ DEFAULT_CIRCLE = 5
10
11
 
11
12
  def self.kuku(args)
12
13
  Kukushka.kuku(args)
@@ -42,7 +43,10 @@ module Kukushka
42
43
  FileUtils.mkdir_p(dir) unless File.exists?(dir)
43
44
  config = {
44
45
  source: source_file,
45
- enabled: true
46
+ enabled: true,
47
+ counter: 0,
48
+ from: 0,
49
+ circle: DEFAULT_CIRCLE,
46
50
  }
47
51
  File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
48
52
  end
@@ -64,10 +68,36 @@ module Kukushka
64
68
  end
65
69
 
66
70
  def source
67
- @source ||= YAML::load_file(CONFIG_FILE)[: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 }
68
99
  end
69
100
 
70
- private
71
101
  def config
72
102
  @config ||= YAML::load_file(CONFIG_FILE)
73
103
  end
@@ -94,10 +124,28 @@ module Kukushka
94
124
  return config.enable if command == 'on'
95
125
  return config.disable if command == 'off'
96
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
+
97
145
  return config.cleanup if command == 'cleanup'
98
146
  # return show if command == 'show'
99
147
  return sample if command == 'sample'
100
- return punchline if command.nil?
148
+ return punchline
101
149
  end
102
150
 
103
151
  private
@@ -115,7 +163,26 @@ module Kukushka
115
163
  # end
116
164
 
117
165
  def sample
118
- @sample ||= File.readlines(config.source, chomp: true).sample
166
+ if config.counter
167
+ config.set_counter(config.counter + 1)
168
+ config.set_counter(0) if config.counter > lines.size
169
+
170
+ if config.counter < config.from
171
+ config.set_counter(config.from)
172
+ end
173
+
174
+ if config.counter >= config.from + config.circle - 1
175
+ config.set_counter(config.from)
176
+ end
177
+
178
+ return "#{lines[config.counter]} #{config.counter}/#{lines.size}"
179
+ end
180
+
181
+ lines.sample
182
+ end
183
+
184
+ def lines
185
+ @lines ||= File.readlines(config.source, chomp: true)
119
186
  end
120
187
 
121
188
  def punchline
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kukushka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak
@@ -40,6 +40,8 @@ files:
40
40
  - README.md
41
41
  - Rakefile
42
42
  - exe/kuku
43
+ - kukushka-0.1.4.gem
44
+ - kukushka-0.1.5.gem
43
45
  - lib/kukushka.rb
44
46
  - lib/kukushka/version.rb
45
47
  - sig/kukushka.rbs