command_timer 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  module CommandTimer
2
2
  class Command
3
+ attr_writer :burn_time
3
4
  attr_accessor :description
4
5
  attr_accessor :content
5
- attr_writer :burn_time
6
+ attr_accessor :observer
6
7
 
7
8
  def burn_time
8
9
  if @burn_time =~ /[0-9]{2}:[0-9]{2}:[0-9]{2}/
@@ -15,6 +16,22 @@ module CommandTimer
15
16
  def exec
16
17
  echo_command
17
18
  system @content
19
+ if @observer
20
+ puts "===================="
21
+ puts "= Start observer, input S to stop it."
22
+ puts "= #{@observer}"
23
+ puts "===================="
24
+ thread = Thread.new do
25
+ system @observer
26
+ end
27
+ thread.run
28
+ input = ""
29
+ until ["s", "S", "stop"].include?(input) do
30
+ input = STDIN.gets.chomp
31
+ end
32
+ thread.kill
33
+ puts "Observer stopped."
34
+ end
18
35
  end
19
36
 
20
37
  def echo_command
@@ -10,12 +10,8 @@ module CommandTimer
10
10
  data = cell[1]
11
11
  command = Command.new
12
12
  data.each do |k, v|
13
- if k == 'content'
14
- command.content = ''
15
- v.each_line do |line|
16
- command.content += line.strip
17
- command.content += ';' unless command.content.end_with?(';')
18
- end
13
+ if ['content', 'observer'].include?(k)
14
+ command.send("#{k}=", parse_commands(v))
19
15
  else
20
16
  command.send("#{k}=", v)
21
17
  end
@@ -24,5 +20,14 @@ module CommandTimer
24
20
  end
25
21
  commands
26
22
  end
23
+
24
+ def self.parse_commands(text)
25
+ commands = ''
26
+ text.each_line do |line|
27
+ commands += line.strip
28
+ commands += ';' unless line.end_with?(';')
29
+ end
30
+ commands
31
+ end
27
32
  end
28
33
  end
@@ -80,6 +80,7 @@ module CommandTimer
80
80
  puts "Be executed by user input"
81
81
  end
82
82
  command.echo_command
83
+ puts "Observer: #{command.observer}" if command.observer
83
84
  end
84
85
  puts "--------------------"
85
86
  puts ""
@@ -1,3 +1,3 @@
1
1
  module CommandTimer
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: