trecs 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87c0b4a09cb4986d22945bf20ddcb8c479f6e8fe
4
- data.tar.gz: ed7c1d258de1fa55960daf9a0feab11d35a3b91c
3
+ metadata.gz: 1e93913cf8aa26ce05001353b89af69efb669077
4
+ data.tar.gz: fe5e85d7bbb1f7ead37800b144eccc53f45db14c
5
5
  SHA512:
6
- metadata.gz: f56ccb909c71150449dbf09ea3d99eb71281380ba0edf1ea14c4da90d39c3161cb0949163163cc519d12a5826f0ea30358086dbbbd3d7032b85e97d7ef9b31df
7
- data.tar.gz: 18a03490b2849ccc036dc5ab01f8cc8788f4793927f01d30cd48faee87d52f283f71b6f41c688ce1db632060b57fe3beda2b379944de3a581260258ff1cca679
6
+ metadata.gz: 6f8c55f1c7bbec1af949c5f0ba745e941ddb14fa28f687486f2c4cc6935127c1f32c1f514c29e15bd51f35ea0c0664f4c069264ed65288ec339cfb603b07fb5b
7
+ data.tar.gz: c65961148fe73d74b266bd3afa60b1e08ab79babbc5b1b430063de859bc6cb54f623b85e17a5349deff08c0203022edd0dba7126df2141cd72f6965d7de64f8d
data/Gemfile.lock CHANGED
@@ -1,55 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.1.4)
4
+ trecs (0.1.5)
5
5
  trollop (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- coderay (1.1.0)
11
10
  diff-lcs (1.2.5)
12
- ffi (1.9.3-java)
13
11
  given_core (3.5.4)
14
12
  sorcerer (>= 0.3.7)
15
- method_source (0.8.2)
16
- pry (0.9.12.6)
17
- coderay (~> 1.0)
18
- method_source (~> 0.8)
19
- slop (~> 3.4)
20
- pry (0.9.12.6-java)
21
- coderay (~> 1.0)
22
- method_source (~> 0.8)
23
- slop (~> 3.4)
24
- spoon (~> 0.0)
25
- pry-nav (0.2.3)
26
- pry (~> 0.9.10)
27
13
  rake (10.3.2)
28
14
  rspec (2.99.0)
29
15
  rspec-core (~> 2.99.0)
30
16
  rspec-expectations (~> 2.99.0)
31
17
  rspec-mocks (~> 2.99.0)
32
- rspec-core (2.99.0)
33
- rspec-expectations (2.99.0)
18
+ rspec-core (2.99.1)
19
+ rspec-expectations (2.99.1)
34
20
  diff-lcs (>= 1.1.3, < 2.0)
35
21
  rspec-given (3.5.4)
36
22
  given_core (= 3.5.4)
37
23
  rspec (>= 2.12)
38
24
  rspec-mocks (2.99.1)
39
- slop (3.5.0)
40
25
  sorcerer (1.0.2)
41
- spoon (0.0.4)
42
- ffi
43
26
  trollop (2.0)
44
27
 
45
28
  PLATFORMS
46
- java
47
29
  ruby
48
30
 
49
31
  DEPENDENCIES
50
32
  bundler (~> 1.6)
51
- pry
52
- pry-nav
53
33
  rake
54
34
  rspec (~> 2.12)
55
35
  rspec-given (~> 3.5.4)
data/bin/trecs_record CHANGED
@@ -9,13 +9,15 @@ require "trollop"
9
9
  opts = Trollop::options do
10
10
  version TRecs::VERSION
11
11
 
12
- opt :step, "Time in ms between frames", short: 's', default: 100
13
- opt :format, "File format", type: String, default: "yaml_store"
14
- opt :strategy, "Strategy", type: String, default: "incremental"
12
+ opt :step, "Time in ms between frames", short: 's', default: 100
13
+ opt :format, "File format", type: String, default: "yaml_store"
14
+ opt :strategy, "Strategy", type: String, default: "incremental"
15
15
 
16
- opt :message, "Message to record", type: String, default: "TRecs!"
17
- opt :input_file, "File to record", type: String, default: ""
18
- opt :terminal, "Launch terminal", default: true
16
+ opt :message, "Message to record", type: String, default: "TRecs!"
17
+ opt :width, "Width", type: Integer, default: 10
18
+ opt :command, "Command" , type: String
19
+ opt :input_file, "File to record", type: String, default: ""
20
+ opt :terminal, "Launch terminal", default: true
19
21
 
20
22
  end
21
23
  opts[:trecs_file] = ARGV[0]
@@ -43,7 +45,7 @@ strategy_class = Kernel.const_get([
43
45
 
44
46
  puts "Recording ..."
45
47
 
46
- if strategy_class == TRecs::TtyrecStrategy
48
+ if strategy_class.to_s == "TRecs::TtyrecStrategy"
47
49
  opts[:height], opts[:width] = `stty size`.split(" ").map(&:to_i)
48
50
  system "ttyrec #{opts[:input_file]}" if opts[:terminal]
49
51
  end
@@ -0,0 +1,52 @@
1
+ require "recording_strategies/strategy"
2
+ require "recording_strategies/shell_command_strategy"
3
+
4
+ module TRecs
5
+ class FlyFromRightStrategy
6
+ include Strategy
7
+ include ShellCommandStrategy
8
+ attr_reader :message
9
+ attr_reader :width
10
+ attr_reader :command
11
+
12
+ def initialize(options={})
13
+ @message = options.fetch(:message)
14
+ @width = options.fetch(:width) { 10 }
15
+
16
+ @width = @message.size if @width < @message.size
17
+
18
+ @command = options.fetch(:command) { nil }
19
+ end
20
+
21
+ def perform
22
+ time = 0
23
+ message.each_char.inject("") do |current_msg, current_char|
24
+ current_time(time)
25
+ current_content(current_msg)
26
+ save_frame
27
+ ((width-1)-current_msg.size).downto(1) do |i|
28
+ time += recorder.step
29
+ content = current_msg + " " * i + current_char
30
+
31
+ current_time(time)
32
+ current_content(content)
33
+ save_frame
34
+ end
35
+
36
+ current_msg += current_char
37
+
38
+ time += recorder.step
39
+ content = current_msg
40
+
41
+ current_time(time)
42
+ current_content(content)
43
+ save_frame
44
+
45
+ time += recorder.step
46
+ content = current_msg
47
+
48
+ current_msg
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,17 +1,22 @@
1
- class HashStrategy
2
- attr_accessor :recorder
3
- attr_accessor :frames
1
+ require "recording_strategies/strategy"
2
+ module TRecs
3
+ class HashStrategy
4
+ include Strategy
5
+ attr_accessor :frames
4
6
 
5
- def initialize(frames)
6
- @frames = frames || Hash.new
7
- end
7
+ def initialize(frames={})
8
+ @frames = frames || Hash.new
9
+ end
8
10
 
9
- def perform
10
- @frames.each do |time, content|
11
- recorder.current_frame(time: time, content: content)
11
+ def perform
12
+ @frames.each do |time, content|
13
+ current_time(time)
14
+ current_content(content)
15
+ save_frame
16
+ end
12
17
  end
13
- end
14
18
 
15
- def stop
19
+ def stop
20
+ end
16
21
  end
17
22
  end
@@ -1,8 +1,10 @@
1
- require "recording_strategy"
1
+ require "recording_strategies/strategy"
2
+
2
3
  module TRecs
3
4
  class IncrementalStrategy
5
+ include Strategy
6
+
4
7
  attr_reader :message
5
- attr_accessor :recorder
6
8
 
7
9
  def initialize(options={})
8
10
  @message = options.fetch(:message)
@@ -13,11 +15,12 @@ module TRecs
13
15
  message.each_char.each_with_object("") do |current_char, current_msg|
14
16
  current_msg << current_char
15
17
 
16
- time = timestamp_for(current_msg)
17
- content = current_msg.dup
18
- recorder.current_frame(time: time, content: content)
18
+ current_time(timestamp_for(current_msg))
19
+ current_content(current_msg.dup)
20
+ save_frame
19
21
  end
20
22
  end
23
+
21
24
  private
22
25
 
23
26
  def timestamp_for(message)
@@ -1,7 +1,7 @@
1
- require "recording_strategy"
1
+ require "recording_strategies/strategy"
2
2
  module TRecs
3
3
  class RawFileStrategy
4
- attr_accessor :recorder
4
+ include Strategy
5
5
  attr_reader :file
6
6
 
7
7
  def initialize(options={})
@@ -21,9 +21,10 @@ module TRecs
21
21
  start_time = clock.now
22
22
 
23
23
  while @recording
24
- time = timestamp(clock.now - start_time)
25
- content = File.read(@file)
26
- recorder.current_frame(time: time, content: content)
24
+ current_time(timestamp(clock.now - start_time))
25
+ current_content(File.read(@file))
26
+ save_frame
27
+
27
28
  custom_sleep(recorder.step)
28
29
  end
29
30
  end
@@ -0,0 +1,11 @@
1
+ module TRecs
2
+ module ShellCommandStrategy
3
+ def current_content(str)
4
+ if command
5
+ comm_array = command.split(" ")
6
+ str = IO.popen([*comm_array, "#{str}"]).read
7
+ end
8
+ super(str)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module TRecs
2
+ module Strategy
3
+ attr_accessor :recorder
4
+
5
+ def stop
6
+ end
7
+
8
+ private
9
+
10
+ attr_accessor :__time
11
+ attr_accessor :__content
12
+
13
+ def current_time(time)
14
+ @__time = time
15
+ end
16
+
17
+ def current_content(content)
18
+ @__content = content
19
+ end
20
+
21
+ def save_frame
22
+ recorder.current_frame(time: __time, content: __content)
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,7 @@
1
+ require "recording_strategies/strategy"
1
2
  module TRecs
2
3
  class TtyrecStrategy
3
- attr_accessor :recorder
4
+ include Strategy
4
5
 
5
6
  def initialize(options={})
6
7
  file = options.fetch(:input_file)
@@ -30,7 +31,9 @@ module TRecs
30
31
  offset = ((curr_timestamp - @first_timestamp)*1000).to_i
31
32
 
32
33
  if curr_timestamp > @prev_timestamp
33
- recorder.current_frame(time: offset, content: frame)
34
+ current_time(offset)
35
+ current_content(frame)
36
+ save_frame
34
37
  @prev_timestamp = curr_timestamp
35
38
  @prev_frame = frame
36
39
  end
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,17 +1,19 @@
1
- class InMemoryWriter
2
- attr_accessor :recorder
3
- attr_reader :frames
1
+ module TRecs
2
+ class InMemoryWriter
3
+ attr_accessor :recorder
4
+ attr_reader :frames
4
5
 
5
- def setup
6
- @frames = {}
7
- end
6
+ def setup
7
+ @frames = {}
8
+ end
8
9
 
9
- def create_frame(options={})
10
- time = options.fetch(:time)
11
- content = options.fetch(:content)
12
- @frames[time] = content
13
- end
10
+ def create_frame(options={})
11
+ time = options.fetch(:time)
12
+ content = options.fetch(:content)
13
+ @frames[time] = content
14
+ end
14
15
 
15
- def render
16
+ def render
17
+ end
16
18
  end
17
19
  end
@@ -7,7 +7,6 @@ module TRecs
7
7
  attr_reader :frames
8
8
  attr_reader :file
9
9
 
10
-
11
10
  def initialize(options={})
12
11
  @file = options.fetch(:trecs_file)
13
12
  FileUtils.rm(@file, force: true)
@@ -0,0 +1,68 @@
1
+ require "spec_helper"
2
+ require "recording_strategies/fly_from_right_strategy"
3
+
4
+ module TRecs
5
+ describe FlyFromRightStrategy do
6
+ context "initialization" do
7
+ When(:strategy1) { FlyFromRightStrategy.new(message: "HELLO") }
8
+ Then { strategy1.message == "HELLO" }
9
+
10
+ When(:strategy2) { FlyFromRightStrategy.new }
11
+ Then { expect(strategy2).to have_failed(KeyError, /message/) }
12
+ end
13
+
14
+ context "with/message relation" do
15
+ context "same size" do
16
+ When(:strategy) { FlyFromRightStrategy.new(message: "HELLO", width: 5) }
17
+ Then { strategy.width == 5 }
18
+ end
19
+
20
+ context "with greater than message" do
21
+ When(:strategy) { FlyFromRightStrategy.new(message: "HELLO", width: 10) }
22
+ Then { strategy.width == 10 }
23
+ end
24
+
25
+ context "with not big enough" do
26
+ When(:strategy) { FlyFromRightStrategy.new(message: "HELLO", width: 2) }
27
+ Then { strategy.width == 5 }
28
+ end
29
+ end
30
+
31
+ context "recorder" do
32
+ Given(:strategy) { FlyFromRightStrategy.new(message: "HELLO") }
33
+ Given(:recorder) { Object.new }
34
+ When { strategy.recorder = recorder }
35
+ Then { strategy.recorder == recorder }
36
+ end
37
+
38
+ context "perform" do
39
+ Given { Spy.clear }
40
+ Given(:recorder) { Spy.new("recorder") }
41
+ Given(:strategy) { FlyFromRightStrategy.new(message: "abc", width: 4) }
42
+
43
+ When { recorder.stub(:step) { 100 } }
44
+ When { strategy.recorder = recorder }
45
+ When { strategy.perform }
46
+
47
+ Then { recorder.calls[1] == [:current_frame, [ {time: 0, content: "" } ] ] }
48
+ Then { recorder.calls[2] == [:current_frame, [ {time: 100, content: " a" } ] ] }
49
+ Then { recorder.calls[3] == [:current_frame, [ {time: 200, content: " a" } ] ] }
50
+ Then { recorder.calls[4] == [:current_frame, [ {time: 300, content: " a" } ] ] }
51
+ Then { recorder.calls[5] == [:current_frame, [ {time: 400, content: "a" } ] ] }
52
+
53
+ Then { recorder.calls[6] == [:current_frame, [ {time: 500, content: "a" } ] ] }
54
+ Then { recorder.calls[7] == [:current_frame, [ {time: 600, content: "a b" } ] ] }
55
+ Then { recorder.calls[8] == [:current_frame, [ {time: 700, content: "a b" } ] ] }
56
+ Then { recorder.calls[9] == [:current_frame, [ {time: 800, content: "ab" } ] ] }
57
+
58
+ Then { recorder.calls[10] == [:current_frame, [ {time: 900, content: "ab" } ] ] }
59
+ Then { recorder.calls[11] == [:current_frame, [ {time: 1000, content: "ab c" } ] ] }
60
+ Then { recorder.calls[12] == [:current_frame, [ {time: 1100, content: "abc" } ] ] }
61
+
62
+ end
63
+
64
+ context "shell command" do
65
+ Then { skip("Test shell command") }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "recording_strategies/hash_strategy"
3
+
4
+ module TRecs
5
+ describe HashStrategy do
6
+ context "initialization" do
7
+ When(:strategy1) { HashStrategy.new({}) }
8
+ Then { strategy1.frames == {} }
9
+
10
+ When(:strategy2) { HashStrategy.new }
11
+ Then { strategy2.frames == {} }
12
+ end
13
+
14
+ context "recorder" do
15
+ Given(:strategy) { HashStrategy.new }
16
+ Given(:recorder) { Object.new }
17
+ When { strategy.recorder = recorder }
18
+ Then { strategy.recorder == recorder }
19
+ end
20
+
21
+ context "perform" do
22
+ Given { Spy.clear }
23
+ Given(:recorder) { Spy.new("recorder") }
24
+ Given(:strategy) { HashStrategy.new(
25
+ {
26
+ 0 => "A",
27
+ 10 => "B",
28
+ 15 => "C",
29
+ }
30
+ ) }
31
+
32
+ When { strategy.recorder = recorder }
33
+ When { strategy.perform }
34
+
35
+ Then { recorder.calls[1] == [:current_frame, [ {time: 0, content: "A"} ] ] }
36
+ Then { recorder.calls[2] == [:current_frame, [ {time: 10, content: "B"} ] ] }
37
+ Then { recorder.calls[3] == [:current_frame, [ {time: 15, content: "C"} ] ] }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+ require "recording_strategies/shell_command_strategy"
3
+
4
+ module TRecs
5
+ describe ShellCommandStrategy do
6
+ context "shell command" do
7
+ Then { skip("Test shell command") }
8
+ end
9
+ end
10
+ end
data/trecs.gemspec CHANGED
@@ -28,6 +28,4 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec", "~> 2.12"
29
29
  spec.add_development_dependency "rspec-given", "~> 3.5.4"
30
30
 
31
- spec.add_development_dependency "pry"
32
- spec.add_development_dependency "pry-nav"
33
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -80,34 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.5.4
83
- - !ruby/object:Gem::Dependency
84
- name: pry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: pry-nav
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
83
  description: Record text screencasts.
112
84
  email:
113
85
  - iachetti.federico@gmail.com
@@ -147,9 +119,12 @@ files:
147
119
  - lib/trecs/readers/yaml_store_reader.rb
148
120
  - lib/trecs/recorder.rb
149
121
  - lib/trecs/recording_strategies/custom_strategy.rb
122
+ - lib/trecs/recording_strategies/fly_from_right_strategy.rb
150
123
  - lib/trecs/recording_strategies/hash_strategy.rb
151
124
  - lib/trecs/recording_strategies/incremental_strategy.rb
152
125
  - lib/trecs/recording_strategies/raw_file_strategy.rb
126
+ - lib/trecs/recording_strategies/shell_command_strategy.rb
127
+ - lib/trecs/recording_strategies/strategy.rb
153
128
  - lib/trecs/recording_strategies/ttyrec_strategy.rb
154
129
  - lib/trecs/screens/terminal_screen.rb
155
130
  - lib/trecs/tickers/terminal_input_ticker.rb
@@ -173,8 +148,11 @@ files:
173
148
  - spec/spec_helper.rb
174
149
  - spec/trecs/player_spec.rb
175
150
  - spec/trecs/recorder_spec.rb
151
+ - spec/trecs/recording_strategies/fly_from_right_strategy_spec.rb
152
+ - spec/trecs/recording_strategies/hash_strategy_spec.rb
176
153
  - spec/trecs/recording_strategies/incremental_strategy_spec.rb
177
154
  - spec/trecs/recording_strategies/raw_file_strategy_spec.rb
155
+ - spec/trecs/recording_strategies/shell_command_strategy_spec.rb
178
156
  - spec/trecs/writers/in_memory_writer_spec.rb
179
157
  - tmp/.gitignore
180
158
  - trecs.gemspec
@@ -208,6 +186,9 @@ test_files:
208
186
  - spec/spec_helper.rb
209
187
  - spec/trecs/player_spec.rb
210
188
  - spec/trecs/recorder_spec.rb
189
+ - spec/trecs/recording_strategies/fly_from_right_strategy_spec.rb
190
+ - spec/trecs/recording_strategies/hash_strategy_spec.rb
211
191
  - spec/trecs/recording_strategies/incremental_strategy_spec.rb
212
192
  - spec/trecs/recording_strategies/raw_file_strategy_spec.rb
193
+ - spec/trecs/recording_strategies/shell_command_strategy_spec.rb
213
194
  - spec/trecs/writers/in_memory_writer_spec.rb