trecs 0.0.8 → 0.0.9

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: 5978e79a6f87a6ce821d9eec6b9d57c499a1fa30
4
- data.tar.gz: 6c62a5294342f194d6e9dfc9e638a896b01952ef
3
+ metadata.gz: e99047b216ec42e9c6b739b7b1563954a71d0a25
4
+ data.tar.gz: 21164adc5f38c05126e72f7296f27ed98fd48a83
5
5
  SHA512:
6
- metadata.gz: d5b0cc0b8ba641d853e0db21f6397de0ee2b8d2e61aa3a68cdf806fd82a42e01486d66026797699a97dbd6b36b84721562d6277f55e6317834a6c7f787ef1976
7
- data.tar.gz: 3a2e735c65145832aae7601ddcd9e3ca3a66ebb643811851a7ed47506629edc589649c9c3d1d316766d0f2c149e35fbdaba6ac1a98a4afba6c089d80f57a8071
6
+ metadata.gz: 3de81b0147f53c3d85092c99e709f52e5d1be3f3b69fcb8892456714ed6b9cce1e606252d60a27219a5ae9a57ebdb94cb9a7ead785e82ebf09031d14723d6530
7
+ data.tar.gz: 384093b957ef8bb64469f2e90768d1101bc0d37d9ab0c3d656a912f970f0b1f6acbac25f120e682e3b8e1613817d33d256dcd7c11c8623aa04d3e77d5bf7ae07
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.0.8)
4
+ trecs (0.0.9)
5
5
  rubyzip (~> 1.1.4)
6
6
  trollop (~> 2.0)
7
7
 
@@ -30,14 +30,13 @@ GEM
30
30
  rspec-given (3.5.4)
31
31
  given_core (= 3.5.4)
32
32
  rspec (>= 2.12)
33
- rspec-mocks (2.99.0)
33
+ rspec-mocks (2.99.1)
34
34
  rubyzip (1.1.4)
35
35
  slop (3.5.0)
36
36
  sorcerer (1.0.2)
37
37
  trollop (2.0)
38
38
 
39
39
  PLATFORMS
40
- java
41
40
  ruby
42
41
 
43
42
  DEPENDENCIES
data/bin/trecs CHANGED
@@ -1,33 +1,47 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift(File.expand_path("../../lib", __FILE__))
4
-
4
+ require "trecs"
5
+ require "player"
5
6
  require "trollop"
6
7
 
7
- require "timestamps"
8
- require "players/zip_file_player"
9
-
10
- options = Trollop::options do
11
- opt :file_name, "File to process", short: 'f', type: String
12
- opt :time, "Frame at time", short: 't', type: String
13
- opt :current_time, "Returns the current playback time", short: 'c'
14
- opt :step, "Time im ms between frames", short: 's', default: 100
15
8
 
16
- opt :timestamps, "Returns the list of existing frame timestamps"
9
+ opts = Trollop::options do
10
+ opt :step, "Time in ms between frames", short: 's', default: 100
11
+ opt :format, "File format", type: String, default: "yaml_store"
12
+ opt :ticker, "Ticker", type: String, default: ""
17
13
 
18
- opt :testing, "Ticks without waiting. Use this option only for testing purpuses"
14
+ opt :ticker_file, "File to watch", type: String, default: "/tmp/ticker"
19
15
  end
16
+ opts[:trecs_file] = ARGV[0]
20
17
 
21
- file_name = options[:file_name]
22
- if file_name
23
- if File.exist?(file_name)
24
- player = TRecs::ZipFilePlayer.new(options)
25
- if options[:timestamps]
26
- p player.timestamps
27
- else
28
- player.play
29
- end
30
- else
31
- puts "File #{file_name} does not exist."
32
- end
33
- end
18
+ reader_file = "readers/#{opts[:format]}_reader"
19
+ require reader_file
20
+ reader_class = Kernel.const_get([
21
+ "TRecs::",
22
+ opts[:format].split(/[-_\s]/).map(&:capitalize),
23
+ "Reader"
24
+ ].join
25
+ )
26
+
27
+
28
+ ticker_separator = '_' unless opts[:ticker] == ''
29
+ ticker_file = "tickers/#{opts[:ticker]}#{ticker_separator}ticker"
30
+ require ticker_file
31
+ ticker_class = Kernel.const_get([
32
+ "TRecs::",
33
+ opts[:ticker].split(/[-_\s]/).map(&:capitalize),
34
+ "Ticker"
35
+ ].join
36
+ )
37
+
38
+ player_options = {
39
+ reader: reader_class.new(opts),
40
+ ticker: ticker_class.new(opts),
41
+ step: opts[:step],
42
+ }
43
+
44
+ #p opts
45
+ #p player_options
46
+ player = TRecs::Player.new(player_options)
47
+ player.play
data/lib/trecs/player.rb CHANGED
@@ -30,12 +30,13 @@ module TRecs
30
30
  end
31
31
 
32
32
  def tick(time=current_time)
33
- content = reader.frame_at(time)
33
+ content = reader.frame_at(time_to_play(time))
34
34
  if content != prev_content
35
35
  screen.clear
36
36
  screen.puts(content)
37
37
  self.prev_content = content
38
38
  end
39
+ content
39
40
  end
40
41
 
41
42
  def timestamps
@@ -44,12 +45,7 @@ module TRecs
44
45
 
45
46
  def time_to_play(time)
46
47
  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
48
+ timestamps.reverse.detect { |t| t <= time }
53
49
  end
54
50
 
55
51
  private
@@ -8,7 +8,8 @@ module TRecs
8
8
  attr_reader :timestamps
9
9
 
10
10
  def initialize(options={})
11
- @file = options.fetch(:file)
11
+ # trecs_file -> output file by convention
12
+ @file = options.fetch(:trecs_file)
12
13
  File.open(@file)
13
14
 
14
15
  store = YAML::Store.new "/tmp/hola.trecs"
@@ -9,6 +9,7 @@ module TRecs
9
9
  end
10
10
 
11
11
  def perform
12
+ recorder.current_frame(time: 0, content: "")
12
13
  message.each_char.each_with_object("") do |current_char, current_msg|
13
14
  current_msg << current_char
14
15
 
@@ -20,7 +21,7 @@ module TRecs
20
21
  private
21
22
 
22
23
  def timestamp_for(message)
23
- (message.size - 1) * recorder.step
24
+ message.size * recorder.step
24
25
  end
25
26
  end
26
27
  end
@@ -1,12 +1,18 @@
1
1
  module TRecs
2
2
  class TerminalInputTicker
3
3
  attr_accessor :player
4
-
4
+ def initialize(*)
5
+ end
6
+
5
7
  def start
6
8
  while (input = gets) =~ /\A[0-9]+\Z/
7
9
  time = input.to_i
8
10
  player.tick(time)
9
11
  end
10
12
  end
13
+ def to_s
14
+ "<#{self.class}>"
15
+ end
16
+ alias :inspect :to_s
11
17
  end
12
18
  end
@@ -1,6 +1,8 @@
1
1
  module TRecs
2
2
  class Ticker
3
3
  attr_accessor :player
4
+ def initialize(*)
5
+ end
4
6
 
5
7
  def start
6
8
  prev_time = 0
@@ -11,5 +13,9 @@ module TRecs
11
13
  end
12
14
  true
13
15
  end
16
+ def to_s
17
+ "<#{self.class}>"
18
+ end
19
+ alias :inspect :to_s
14
20
  end
15
21
  end
@@ -0,0 +1,30 @@
1
+ require "fileutils"
2
+ module TRecs
3
+ class WatchFileTicker
4
+ attr_accessor :player
5
+ def initialize(opts={})
6
+ @watch_file = opts.fetch(:ticker_file)
7
+ FileUtils.touch(@watch_file)
8
+ File.open(@watch_file, "w") do |f|
9
+ f.write("0")
10
+ end
11
+ @step = opts.fetch(:step)
12
+ end
13
+
14
+ def start
15
+ while input =~ /\A[0-9]+\Z/
16
+ time = input.to_i
17
+ player.tick(time)
18
+ sleep(@step/1000.0)
19
+ end
20
+ end
21
+ def to_s
22
+ "<#{self.class}>"
23
+ end
24
+ alias :inspect :to_s
25
+ private
26
+ def input
27
+ File.read(@watch_file).chomp
28
+ end
29
+ end
30
+ end
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -8,7 +8,7 @@ module TRecs
8
8
 
9
9
 
10
10
  def initialize(options={})
11
- @file = options.fetch(:file)
11
+ @file = options.fetch(:trecs_file)
12
12
  FileUtils.rm(@file, force: true)
13
13
  end
14
14
 
data/lib/trecs.rb CHANGED
@@ -1,3 +1 @@
1
1
  $:.unshift(File.expand_path("../trecs/", __FILE__))
2
-
3
- require "pry"
Binary file
@@ -74,7 +74,7 @@ module TRecs
74
74
  end
75
75
 
76
76
  context "content at time" do
77
- Given(:screen) { OpenStruct.new }
77
+ Given(:screen) { double.as_null_object }
78
78
  Given(:ticker) { OpenStruct.new }
79
79
  Given(:reader) { CustomReader.new(0 => "a", 100 => "b", 200 => "c") }
80
80
 
@@ -82,16 +82,29 @@ module TRecs
82
82
  Player.new(reader: reader, ticker: ticker, screen: screen)
83
83
  }
84
84
 
85
- #When { player.play }
86
-
87
85
  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 }
86
+
87
+ Then { player.time_to_play(nil) == 0 }
88
+ Then { player.tick(nil) == "a" }
89
+
90
+ Then { player.time_to_play(0) == 0 }
91
+ Then { player.tick(0) == "a" }
92
+
93
+ Then { player.time_to_play(100) == 100 }
94
+ Then { player.tick(100) == "b" }
95
+
96
+ Then { player.time_to_play(50) == 0 }
97
+ Then { player.tick(50) == "a" }
98
+
99
+ Then { player.time_to_play(101) == 100 }
100
+ Then { player.tick(101) == "b" }
101
+
102
+ Then { player.time_to_play(199) == 100 }
103
+ Then { player.tick(199) == "b" }
104
+
94
105
  Then { player.time_to_play(1000) == 200 }
106
+ Then { player.tick(1000) == "c" }
107
+
95
108
  end
96
109
  end
97
110
  end
@@ -27,17 +27,18 @@ module TRecs
27
27
  When { strategy.recorder = recorder }
28
28
  When { strategy.perform }
29
29
 
30
- Then { recorder.calls[1] == [:current_frame, [ {time: 0, content: "H"} ] ] }
31
- Then { recorder.calls[2] == [:current_frame, [ {time: 100, content: "He"} ] ] }
32
- Then { recorder.calls[3] == [:current_frame, [ {time: 200, content: "Hel"} ] ] }
33
- Then { recorder.calls[4] == [:current_frame, [ {time: 300, content: "Hell"} ] ] }
34
- Then { recorder.calls[5] == [:current_frame, [ {time: 400, content: "Hello"} ] ] }
35
- Then { recorder.calls[6] == [:current_frame, [ {time: 500, content: "Hello "} ] ] }
36
- Then { recorder.calls[7] == [:current_frame, [ {time: 600, content: "Hello W"} ] ] }
37
- Then { recorder.calls[8] == [:current_frame, [ {time: 700, content: "Hello Wo"} ] ] }
38
- Then { recorder.calls[9] == [:current_frame, [ {time: 800, content: "Hello Wor"} ] ] }
39
- Then { recorder.calls[10] == [:current_frame, [ {time: 900, content: "Hello Worl"} ] ] }
40
- Then { recorder.calls[11] == [:current_frame, [ {time: 1000, content: "Hello World"} ] ] }
30
+ Then { recorder.calls[1] == [:current_frame, [ {time: 0, content: ""} ] ] }
31
+ Then { recorder.calls[2] == [:current_frame, [ {time: 100, content: "H"} ] ] }
32
+ Then { recorder.calls[3] == [:current_frame, [ {time: 200, content: "He"} ] ] }
33
+ Then { recorder.calls[4] == [:current_frame, [ {time: 300, content: "Hel"} ] ] }
34
+ Then { recorder.calls[5] == [:current_frame, [ {time: 400, content: "Hell"} ] ] }
35
+ Then { recorder.calls[6] == [:current_frame, [ {time: 500, content: "Hello"} ] ] }
36
+ Then { recorder.calls[7] == [:current_frame, [ {time: 600, content: "Hello "} ] ] }
37
+ Then { recorder.calls[8] == [:current_frame, [ {time: 700, content: "Hello W"} ] ] }
38
+ Then { recorder.calls[9] == [:current_frame, [ {time: 800, content: "Hello Wo"} ] ] }
39
+ Then { recorder.calls[10] == [:current_frame, [ {time: 900, content: "Hello Wor"} ] ] }
40
+ Then { recorder.calls[11] == [:current_frame, [ {time: 1000, content: "Hello Worl"} ] ] }
41
+ Then { recorder.calls[12] == [:current_frame, [ {time: 1100, content: "Hello World"} ] ] }
41
42
  end
42
43
  end
43
44
  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.0.8
4
+ version: 0.0.9
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-17 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -166,6 +166,7 @@ files:
166
166
  - lib/trecs/screens/terminal_screen.rb
167
167
  - lib/trecs/tickers/terminal_input_ticker.rb
168
168
  - lib/trecs/tickers/ticker.rb
169
+ - lib/trecs/tickers/watch_file_ticker.rb
169
170
  - lib/trecs/version.rb
170
171
  - lib/trecs/writers/in_memory_writer.rb
171
172
  - lib/trecs/writers/yaml_store_writer.rb
@@ -184,6 +185,7 @@ files:
184
185
  - pkg/trecs-0.0.5.gem
185
186
  - pkg/trecs-0.0.6.gem
186
187
  - pkg/trecs-0.0.7.gem
188
+ - pkg/trecs-0.0.8.gem
187
189
  - sandbox/create_recording.rb
188
190
  - sandbox/lipsum_end
189
191
  - sandbox/lipsum_start