trecs 0.0.7 → 0.0.8

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: a6a8efdafc7509e125414076402861a4629e5993
4
- data.tar.gz: f1bc5dca1ffcae32d2bfc113dd56123af12fce9e
3
+ metadata.gz: 5978e79a6f87a6ce821d9eec6b9d57c499a1fa30
4
+ data.tar.gz: 6c62a5294342f194d6e9dfc9e638a896b01952ef
5
5
  SHA512:
6
- metadata.gz: 28ad5ee613f0cdb46081a9653f4866ce46a150a2279b336ce7b12bf504c3e18ee8f1558563815484d8402e8d918af856d626979c7d46fbed47d4db8de5eff8d0
7
- data.tar.gz: 8723b3ffc0c078c66c701d8cdf6c4d09239f6d5e3b84af18291dfeff61de5a8b8051603d057d29f7b2b5a55b35a48d87b91e59d03b00b30c0cb1b4a327cca7d9
6
+ metadata.gz: d5b0cc0b8ba641d853e0db21f6397de0ee2b8d2e61aa3a68cdf806fd82a42e01486d66026797699a97dbd6b36b84721562d6277f55e6317834a6c7f787ef1976
7
+ data.tar.gz: 3a2e735c65145832aae7601ddcd9e3ca3a66ebb643811851a7ed47506629edc589649c9c3d1d316766d0f2c149e35fbdaba6ac1a98a4afba6c089d80f57a8071
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.0.7)
4
+ trecs (0.0.8)
5
5
  rubyzip (~> 1.1.4)
6
6
  trollop (~> 2.0)
7
7
 
data/lib/trecs/player.rb CHANGED
@@ -31,98 +31,31 @@ module TRecs
31
31
 
32
32
  def tick(time=current_time)
33
33
  content = reader.frame_at(time)
34
- if content != @prev_content
34
+ if content != prev_content
35
35
  screen.clear
36
36
  screen.puts(content)
37
- @prev_content = content
37
+ self.prev_content = content
38
38
  end
39
39
  end
40
40
 
41
41
  def timestamps
42
- reader.timestamps
42
+ @timestamps ||= reader.timestamps
43
43
  end
44
-
44
+
45
+ def time_to_play(time)
46
+ time = time.to_i
47
+ return time if timestamps.include? time
48
+ result = timestamps.each_cons(2).select do |min, max|
49
+ time > min && time < max
50
+ end
51
+ result = result.first
52
+ result ? result.first : timestamps.last
53
+ end
54
+
45
55
  private
46
56
  attr_writer :current_time
47
- attr_reader :testing
57
+ attr_reader :testing
58
+ attr_accessor :prev_content
48
59
 
49
60
  end
50
61
  end
51
-
52
-
53
- # require "timestamps"
54
- # require "screens/terminal_screen"
55
-
56
- # module TRecs
57
- # class Player
58
- # attr_reader :screen
59
-
60
- # def initialize(options={})
61
- # time = options.fetch(:time) { nil }
62
- # @current_time = time
63
- # @step = options.fetch(:step) { 100 }
64
- # @screen = options.fetch(:screen) { TerminalScreen.new }
65
- # @testing = options.fetch(:testing) { false }
66
- # @ticks = time ? Array(time.to_i) : ticks
67
- # end
68
-
69
- # def play
70
- # ticks.each do |time|
71
- # play_frame(time)
72
- # sleep(sleep_time) unless testing
73
- # end
74
- # end
75
-
76
- # def tick(time=current_time)
77
- # self.current_time = time
78
- # get_frame(time)
79
- # end
80
-
81
- # def timestamps
82
- # @timestamps ||= get_timestamps.sort
83
- # end
84
-
85
- # def generate_ticks
86
- # ticks = [0]
87
- # curr = 0
88
- # while(curr < timestamps.last.to_i)
89
- # curr += step
90
- # ticks << curr
91
- # end
92
- # ticks
93
- # end
94
-
95
- # def ticks
96
- # @ticks ||= generate_ticks
97
- # end
98
-
99
- # def play_frame(time)
100
- # screen.clear
101
- # screen.puts tick(time_at(time))
102
- # end
103
-
104
- # def time_at(time)
105
- # Timestamps.new(timestamps).time_at(time)
106
- # end
107
-
108
- # private
109
- # attr_accessor :current_time
110
- # attr_reader :step
111
- # attr_reader :testing
112
-
113
-
114
-
115
- # def get_timestamps
116
- # []
117
- # end
118
-
119
- # def get_frame(time)
120
- # ""
121
- # end
122
-
123
- # def sleep_time
124
- # # TODO: Fix this to use the current time
125
- # @sleep_time ||= (step/1000.0)*0.8
126
- # end
127
- # end
128
- # end
@@ -0,0 +1,34 @@
1
+ require 'yaml/store'
2
+
3
+ module TRecs
4
+ class YamlStoreReader
5
+ attr_accessor :player
6
+ attr_reader :frames
7
+ attr_reader :file
8
+ attr_reader :timestamps
9
+
10
+ def initialize(options={})
11
+ @file = options.fetch(:file)
12
+ File.open(@file)
13
+
14
+ store = YAML::Store.new "/tmp/hola.trecs"
15
+ @frames = store.transaction do
16
+ store["frames"]
17
+ end
18
+ @timestamps = @frames.keys
19
+ end
20
+
21
+ def setup
22
+ true
23
+ end
24
+
25
+ def frame_at(time)
26
+ @frames[time]
27
+ end
28
+
29
+ def to_s
30
+ "<#{self.class}>"
31
+ end
32
+ alias :inspect :to_s
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ module TRecs
2
+ class TerminalInputTicker
3
+ attr_accessor :player
4
+
5
+ def start
6
+ while (input = gets) =~ /\A[0-9]+\Z/
7
+ time = input.to_i
8
+ player.tick(time)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module TRecs
2
+ class Ticker
3
+ attr_accessor :player
4
+
5
+ def start
6
+ prev_time = 0
7
+ player.timestamps.each do |time|
8
+ player.tick(time)
9
+ sleep((time - prev_time)/1000.0)
10
+ prev_time = time
11
+ end
12
+ true
13
+ end
14
+ end
15
+ end
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,32 @@
1
+ require 'yaml/store'
2
+
3
+ module TRecs
4
+ class YamlStoreWriter
5
+ attr_accessor :recorder
6
+ attr_reader :frames
7
+ attr_reader :file
8
+
9
+
10
+ def initialize(options={})
11
+ @file = options.fetch(:file)
12
+ FileUtils.rm(@file, force: true)
13
+ end
14
+
15
+ def setup
16
+ @frames = {}
17
+ end
18
+
19
+ def create_frame(options={})
20
+ time = options.fetch(:time)
21
+ content = options.fetch(:content)
22
+ @frames[time] = content
23
+ end
24
+
25
+ def render
26
+ store = YAML::Store.new file
27
+ store.transaction do
28
+ store["frames"] = @frames
29
+ end
30
+ end
31
+ end
32
+ end
Binary file
data/spec/spec_helper.rb CHANGED
@@ -84,6 +84,10 @@ class CustomReader
84
84
  def frame_at(n)
85
85
  @frames[n]
86
86
  end
87
+
88
+ def timestamps
89
+ @frames.keys
90
+ end
87
91
  def setup
88
92
  end
89
93
  end
@@ -72,5 +72,26 @@ module TRecs
72
72
  Then { screen.calls.size == 4 }
73
73
  end
74
74
  end
75
+
76
+ context "content at time" do
77
+ Given(:screen) { OpenStruct.new }
78
+ Given(:ticker) { OpenStruct.new }
79
+ Given(:reader) { CustomReader.new(0 => "a", 100 => "b", 200 => "c") }
80
+
81
+ Given(:player) {
82
+ Player.new(reader: reader, ticker: ticker, screen: screen)
83
+ }
84
+
85
+ #When { player.play }
86
+
87
+ Then { player.timestamps == [0, 100, 200] }
88
+ Then { player.time_to_play(nil) == 0 }
89
+ Then { player.time_to_play(0) == 0 }
90
+ Then { player.time_to_play(100) == 100 }
91
+ Then { player.time_to_play(50) == 0 }
92
+ Then { player.time_to_play(101) == 100 }
93
+ Then { player.time_to_play(199) == 100 }
94
+ Then { player.time_to_play(1000) == 200 }
95
+ end
75
96
  end
76
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
@@ -156,6 +156,7 @@ files:
156
156
  - lib/timestamps.rb
157
157
  - lib/trecs.rb
158
158
  - lib/trecs/player.rb
159
+ - lib/trecs/readers/yaml_store_reader.rb
159
160
  - lib/trecs/recorder.rb
160
161
  - lib/trecs/recording_strategies/custom_strategy.rb
161
162
  - lib/trecs/recording_strategies/hash_strategy.rb
@@ -163,8 +164,11 @@ files:
163
164
  - lib/trecs/recording_strategies/raw_file_strategy.rb
164
165
  - lib/trecs/recording_strategies/ttyrec_recording_strategy.rb
165
166
  - lib/trecs/screens/terminal_screen.rb
167
+ - lib/trecs/tickers/terminal_input_ticker.rb
168
+ - lib/trecs/tickers/ticker.rb
166
169
  - lib/trecs/version.rb
167
170
  - lib/trecs/writers/in_memory_writer.rb
171
+ - lib/trecs/writers/yaml_store_writer.rb
168
172
  - lib/trecs/writers/zip_file_writer.rb
169
173
  - old_specs/player_spec.rb
170
174
  - old_specs/recorders/zip_file_recorder_spec.rb
@@ -179,6 +183,7 @@ files:
179
183
  - pkg/trecs-0.0.4.gem
180
184
  - pkg/trecs-0.0.5.gem
181
185
  - pkg/trecs-0.0.6.gem
186
+ - pkg/trecs-0.0.7.gem
182
187
  - sandbox/create_recording.rb
183
188
  - sandbox/lipsum_end
184
189
  - sandbox/lipsum_start