kukushka 0.1.3 → 0.1.5

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: 19ee15ee498f6251378c39480c444922c0675d192582e17b9695949bd0b0f9ba
4
- data.tar.gz: a163b7deab7dce96ed2ae54214e64b80f66bca400c8c92dc04bc8f3d5258bf92
3
+ metadata.gz: d030697e9f1111877140f181beeeea09d6167a2a4bd4aeab2d17cf6d4c355c2c
4
+ data.tar.gz: a12340d1ec1a48292e0b3e22b2ffac82fa7e5273f7b286f1fc3da940a378e79d
5
5
  SHA512:
6
- metadata.gz: a56fac80db7137a85fceca5520a35242a36cbee6612893ce0f7066343432003aca1736df797aaa8bb7936122465b782b6520b13f639b8712322ea3fe87db079a
7
- data.tar.gz: 6c29a9ddf610115b4553678c7a5f8cf1806df55f82aa86ee4edbf3ed81c7864693b65194ccbb1dcb3d1f692a64afe2c826dec58a8cc4605ac97913a7471a3ab0
6
+ metadata.gz: f25df4940db25abd1a34b886adf32dd34d412cdffb8082b48da325d75b8dd1265f4358f3cc7b23c012347040e0c975146d4be8ba5cc4557106ccf221248c27b9
7
+ data.tar.gz: c98bd1748f07f2fb26e7336a31b5f939ea48f3d3efc5d7aa55a75141f5b697f4fd01261fa026e9eebe55988173744351f9684f3ed8ce7d6e6a1384a1b8bd5fa6
data/README.md CHANGED
@@ -36,3 +36,13 @@ function precmd() {
36
36
  }
37
37
  ```
38
38
 
39
+
40
+
41
+ ```
42
+ mkdir tmp/sk
43
+ cd tmp/sk
44
+ bundle init
45
+
46
+ gem 'pry'
47
+ gem 'kukushka', path: '/Users/Siarhei/laboratory/kukushka'
48
+ ```
data/exe/kuku CHANGED
@@ -5,7 +5,6 @@ require 'pry'
5
5
 
6
6
  if ARGV.join('') == 'on'
7
7
  Kukushka.on!
8
- exit
9
8
  end
10
9
 
11
10
  return unless Kukushka.on?
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
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)
@@ -20,12 +21,12 @@ module Kukushka
20
21
  Config.new.enable
21
22
  end
22
23
 
23
-
24
24
  class Config
25
25
  CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
26
26
  CONFIG_DIR = File.dirname(CONFIG_FILE)
27
27
 
28
28
  def on?
29
+ return true unless exists?
29
30
  exists? && config[:enabled]
30
31
  end
31
32
 
@@ -33,8 +34,8 @@ module Kukushka
33
34
  File.exists?(CONFIG_DIR)
34
35
  end
35
36
 
36
- def init
37
- source_file = param1
37
+ def init(source_file)
38
+ source_file ||= File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
38
39
  return INIT_CTA if source_file.nil?
39
40
  return PROVIDE_SOURCE_CTA unless File.exist?(source_file)
40
41
 
@@ -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
@@ -87,17 +117,35 @@ module Kukushka
87
117
  attr_reader :command, :param1, :config
88
118
 
89
119
  def kuku
90
- config.init if command == 'init'
120
+ config.init(param1) if command == 'init'
91
121
 
92
122
  return INIT_CTA unless config.exists?
93
123
 
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 "#{config.counter}. #{lines[config.counter]}"
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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak
@@ -40,6 +40,7 @@ files:
40
40
  - README.md
41
41
  - Rakefile
42
42
  - exe/kuku
43
+ - kukushka-0.1.4.gem
43
44
  - lib/kukushka.rb
44
45
  - lib/kukushka/version.rb
45
46
  - sig/kukushka.rbs