rsox-command 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ require 'active_support/core_ext/object/blank'
8
8
  require 'active_support/core_ext/enumerable'
9
9
  require 'active_support/core_ext/module/delegation'
10
10
 
11
+ require 'sox/core_ext'
12
+
11
13
  require 'sox/command'
12
14
  require 'sox/stats'
13
-
@@ -0,0 +1,3 @@
1
+ class Float
2
+ INFINITY = 1.0/00
3
+ end unless defined?(Float::INFINITY)
@@ -59,7 +59,15 @@ module Sox
59
59
  @attributes ||=
60
60
  begin
61
61
  paires = raw_values.collect do |key, _, value|
62
- value = value.to_f if value =~ /^-?[0-9.]+$/
62
+ value = case value
63
+ when /^-?[0-9.]+$/
64
+ value.to_f
65
+ when "-inf"
66
+ -Float::INFINITY
67
+ else
68
+ value
69
+ end
70
+
63
71
  [key, value]
64
72
  end
65
73
  Hash[paires]
@@ -92,8 +100,8 @@ module Sox
92
100
  attributes['Pk lev dB']
93
101
  end
94
102
 
95
- def silent?
96
- rms_peak < -45
103
+ def silent?(minimum_rms_peak = -45)
104
+ rms_peak < minimum_rms_peak
97
105
  end
98
106
 
99
107
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rsox-command"
6
- s.version = "0.0.4"
6
+ s.version = "0.0.5"
7
7
  s.authors = ["Alban Peignier"]
8
8
  s.email = ["alban@tryphon.eu"]
9
9
  s.homepage = "http://projects.tryphon.eu/rsox-command"
@@ -5,9 +5,9 @@ describe Sox::Stats do
5
5
  subject { Sox::Stats.new }
6
6
 
7
7
  let(:file) { "spec/fixtures/test.ogg" }
8
-
8
+
9
9
  describe "#raw_output" do
10
-
10
+
11
11
  it "should return sox command output" do
12
12
  subject.input(file)
13
13
  subject.raw_output.should == IO.read("spec/fixtures/test.stats")
@@ -32,11 +32,11 @@ describe Sox::Stats do
32
32
  after(:each) do
33
33
  FileUtils.rm_f "spec/fixtures/test.ogg.stats"
34
34
  end
35
-
35
+
36
36
  end
37
37
 
38
38
  describe "#attributes" do
39
-
39
+
40
40
  it "should read name and first value from raw output" do
41
41
  subject.stub :raw_output => "A key in dB -3"
42
42
  subject.attributes["A key in dB"].should == -3
@@ -66,21 +66,32 @@ describe Sox::Stats do
66
66
  end
67
67
 
68
68
  describe "rms_level" do
69
-
69
+
70
70
  it "should return 'RMS lev dB' found by sox" do
71
71
  subject.stub :attributes => { 'RMS lev dB' => -3.0 }
72
72
  subject.rms_level.should == -3.0
73
73
  end
74
74
 
75
+ it "should return -INFINITY when sox reports '-inf'" do
76
+ subject.stub :raw_values => [[ 'RMS lev dB', '', "-inf" ]]
77
+ subject.rms_level.should == -Float::INFINITY
78
+ end
79
+
75
80
  end
76
81
 
82
+
77
83
  describe "peak_level" do
78
-
84
+
79
85
  it "should return 'Pk lev dB' found by sox" do
80
86
  subject.stub :attributes => { 'Pk lev dB' => -3.0 }
81
87
  subject.peak_level.should == -3.0
82
88
  end
83
89
 
90
+ it "should return -INFINITY when sox reports '-inf'" do
91
+ subject.stub :raw_values => [[ 'Pk lev dB', '', "-inf" ]]
92
+ subject.peak_level.should == -Float::INFINITY
93
+ end
94
+
84
95
  end
85
-
96
+
86
97
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsox-command
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alban Peignier
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-07-19 00:00:00 Z
18
+ date: 2013-09-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -122,6 +122,7 @@ files:
122
122
  - bin/silent-files
123
123
  - lib/rsox-command.rb
124
124
  - lib/sox/command.rb
125
+ - lib/sox/core_ext.rb
125
126
  - lib/sox/stats.rb
126
127
  - rsox-command.gemspec
127
128
  - spec/fixtures/test.ogg