srt_parser 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/srt_parser.rb +31 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bb0db13feec573472906bb0aabf6d942557d410
4
- data.tar.gz: 51611978d6b16d796aa20640709b65065090acfe
3
+ metadata.gz: dfde2d4fb6802520fbbcf15899809c0f8d6da543
4
+ data.tar.gz: 719f1efc0d82966639736e340223396cdee08c43
5
5
  SHA512:
6
- metadata.gz: f0fc68fd758fd66391f2edfa3e81250c49bdc8a17849aa32f143f7718873355614b576931ea97c7279d8f44f80ddd7a545084e06c8094394fe43500dc8b4946f
7
- data.tar.gz: f05c3017d59aecf6155579963881837e2f3d253c2f6a9dbf6b0293449f9c53c0bf6a6162aba93fa8a846f5ce3eb5de02ee940920aa7fd09ce51d501085382458
6
+ metadata.gz: 77da072305d56964f8392e562e84a6791f0cceedef84c6fde028098025438c56e010fdab31945c01c8a476bcc9c2015beb84cd428d349b89e42b29bd4756b6d5
7
+ data.tar.gz: 83d37b291df3f3438ee412a068de2fdea8432b9658a825b47f7e02a63f3c0598022419353fb4b14d9e315e771c4393f37828db3e4e1907c5742a3766f1a7564b
data/lib/srt_parser.rb CHANGED
@@ -10,11 +10,9 @@ module SRTParser
10
10
 
11
11
  srt_file.lines.each do |line|
12
12
  if times.last and line.start_time <= times.last[1]
13
- if line.end_time > times.last[1]
14
- times.last[1] = line.end_time
15
- end
13
+ times.last[1] = [times.last[1], line.end_time].max
16
14
  else
17
- times.push([ line.start_time, line.end_time ])
15
+ times.push([line.start_time, line.end_time])
18
16
  end
19
17
  end
20
18
 
@@ -28,6 +26,14 @@ module SRTParser
28
26
  @intervals = intervals
29
27
  end
30
28
 
29
+ # Accessors:
30
+ def duration
31
+ @duration
32
+ end
33
+ def intervals
34
+ @intervals
35
+ end
36
+
31
37
  def coverage
32
38
  covered = 0
33
39
  @intervals.each do |interval|
@@ -36,5 +42,26 @@ module SRTParser
36
42
 
37
43
  covered / @duration
38
44
  end
45
+
46
+ # Merge lists of intervals. Going to this in a very disgusting way:
47
+ def self.merge(*subtitles)
48
+ intervals = subtitles.map { |subtitle| subtitle.intervals }
49
+ .inject([]) { |all, intervals| all.concat(intervals) }
50
+ .sort_by { |interval| interval[0] }
51
+
52
+ # Start merging the intervals. Totally not DRY:
53
+ times = []
54
+
55
+ intervals.each do |interval|
56
+ if times.last and interval[0] <= times.last[1]
57
+ times.last[1] = [times.last[1], interval[1]].max
58
+ else
59
+ times.push(Array.new(interval))
60
+ end
61
+ end
62
+
63
+ durations = subtitles.map { |subtitle| subtitle.duration }
64
+ Subtitle.new(durations.max, times)
65
+ end
39
66
  end
40
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srt_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Zhao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: srt