popcap 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +4 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +52 -0
  5. data/LICENSE +9 -0
  6. data/README.md +137 -0
  7. data/lib/pop_cap/audio_file.rb +100 -0
  8. data/lib/pop_cap/commander.rb +64 -0
  9. data/lib/pop_cap/converter.rb +40 -0
  10. data/lib/pop_cap/ffmpeg.rb +130 -0
  11. data/lib/pop_cap/fileable.rb +134 -0
  12. data/lib/pop_cap/formatters/bit_rate.rb +29 -0
  13. data/lib/pop_cap/formatters/date.rb +42 -0
  14. data/lib/pop_cap/formatters/duration.rb +44 -0
  15. data/lib/pop_cap/formatters/filesize.rb +69 -0
  16. data/lib/pop_cap/formatters.rb +33 -0
  17. data/lib/pop_cap/helper.rb +53 -0
  18. data/lib/pop_cap/tag_key.rb +32 -0
  19. data/lib/pop_cap/tag_line.rb +36 -0
  20. data/lib/pop_cap/tag_struct.rb +45 -0
  21. data/lib/pop_cap/taggable.rb +100 -0
  22. data/lib/pop_cap/version.rb +3 -0
  23. data/lib/popcap.rb +5 -0
  24. data/popcap.gemspec +27 -0
  25. data/spec/integration/convert_audio_file_spec.rb +15 -0
  26. data/spec/integration/read_metatags_spec.rb +12 -0
  27. data/spec/integration/update_metatags_spec.rb +20 -0
  28. data/spec/lib/pop_cap/audio_file_spec.rb +72 -0
  29. data/spec/lib/pop_cap/commander_spec.rb +64 -0
  30. data/spec/lib/pop_cap/converter_spec.rb +67 -0
  31. data/spec/lib/pop_cap/ffmpeg_spec.rb +96 -0
  32. data/spec/lib/pop_cap/fileable_spec.rb +118 -0
  33. data/spec/lib/pop_cap/formatters/bit_rate_spec.rb +53 -0
  34. data/spec/lib/pop_cap/formatters/date_spec.rb +74 -0
  35. data/spec/lib/pop_cap/formatters/duration_spec.rb +64 -0
  36. data/spec/lib/pop_cap/formatters/filesize_spec.rb +89 -0
  37. data/spec/lib/pop_cap/formatters_spec.rb +36 -0
  38. data/spec/lib/pop_cap/helper_spec.rb +42 -0
  39. data/spec/lib/pop_cap/tag_key_spec.rb +48 -0
  40. data/spec/lib/pop_cap/tag_line_spec.rb +26 -0
  41. data/spec/lib/pop_cap/tag_struct_spec.rb +50 -0
  42. data/spec/lib/pop_cap/taggable_spec.rb +62 -0
  43. data/spec/spec_helper.rb +11 -0
  44. data/spec/support/popcap_spec_helper.rb +86 -0
  45. data/spec/support/reek_spec.rb +8 -0
  46. data/spec/support/sample.flac +0 -0
  47. metadata +163 -0
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'pop_cap/helper'
3
+
4
+ module PopCap
5
+ describe Helper do
6
+ context '#camelize' do
7
+ it 'converts to CamelCase' do
8
+ helper = Helper.new('one_two')
9
+ expect(helper.camelize).to eq('OneTwo')
10
+ end
11
+
12
+ it 'handles symbols' do
13
+ helper = Helper.new(:one_two_three)
14
+ expect(helper.camelize).to eq('OneTwoThree')
15
+ end
16
+ end
17
+
18
+ context '#namespace' do
19
+ it 'accounts for namespacing with a forward slash' do
20
+ helper = Helper.new('one/two/three_four')
21
+ expect(helper.namespace).to eq('One::Two::ThreeFour')
22
+ end
23
+
24
+ it 'accounts for mixed case in namespacing' do
25
+ helper = Helper.new('One/Two/Three_Four')
26
+ expect(helper.namespace).to eq('One::Two::ThreeFour')
27
+ end
28
+ end
29
+
30
+ context '#constantize' do
31
+ it 'converts to a constant' do
32
+ helper = Helper.new('array')
33
+ expect(helper.constantize).to eq(Array)
34
+ end
35
+
36
+ it 'handles module namespacing' do
37
+ helper = Helper.new('file/stat')
38
+ expect(helper.constantize).to eq(File::Stat)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'pop_cap/tag_key'
3
+
4
+ module PopCap
5
+ describe TagKey do
6
+ context '#format' do
7
+ it 'is downcased' do
8
+ expect(TagKey.new('UPCASE').format).to eq(:upcase)
9
+ end
10
+
11
+ it 'is symbolized' do
12
+ expect(TagKey.new('symbol').format).to eq(:symbol)
13
+ end
14
+
15
+ it 'removes "TAG:" if at beginning of string' do
16
+ expect(TagKey.new('TAG:artist').format).to eq(:artist)
17
+ end
18
+
19
+ it 'does remove "TAG:" if not at beginning of string' do
20
+ expect(TagKey.new('TAG:fooTAG:').format).to eq(:"footag:")
21
+ end
22
+
23
+ it 'renames "size" to "filesize" if at beginning of line' do
24
+ expect(TagKey.new('size').format).to eq(:filesize)
25
+ end
26
+
27
+ it 'does not rename "size" to "filesize" if not at beginning of line' do
28
+ expect(TagKey.new('cosize').format).to eq(:cosize)
29
+ end
30
+
31
+ it 'renames "size" to "filesize" if word boundary' do
32
+ expect(TagKey.new('size dot').format).to eq(:"filesize dot")
33
+ end
34
+
35
+ it 'does not rename "size" to "filesize" if not word boundary' do
36
+ expect(TagKey.new('sizedot').format).to eq(:sizedot)
37
+ end
38
+
39
+ it 'returns empty string if empty' do
40
+ expect(TagKey.new('').format).to eq('')
41
+ end
42
+
43
+ it 'returns empty string if nil' do
44
+ expect(TagKey.new(nil).format).to eq('')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'pop_cap/tag_line'
3
+
4
+ module PopCap
5
+ describe TagLine do
6
+ it 'builds a hash by splitting on first equal sign' do
7
+ tl = TagLine.new('one=two=four')
8
+ expect(tl.to_hash).to eq({one: 'two=four'})
9
+ end
10
+
11
+ it 'returns an empty hash for empty string' do
12
+ tl = TagLine.new('')
13
+ expect(tl.to_hash).to eq({})
14
+ end
15
+
16
+ it 'returns an empty hash for nil' do
17
+ tl = TagLine.new(nil)
18
+ expect(tl.to_hash).to eq({})
19
+ end
20
+
21
+ it 'return an empty hash if no equal sign in string' do
22
+ tl = TagLine.new('onetwofour')
23
+ expect(tl.to_hash).to eq({})
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'pop_cap/tag_struct'
3
+
4
+ module PopCap
5
+ describe TagStruct do
6
+ let(:hash) { {artist: 'Artist', date: 1984} }
7
+ let(:ts) { TagStruct.new(hash) }
8
+
9
+ describe '#new' do
10
+ it 'raises error if not a hash' do
11
+ expect do
12
+ TagStruct.new(Array)
13
+ end.to raise_error(ArgumentError, 'Initialize with a hash.')
14
+ end
15
+ end
16
+
17
+ it 'defines methods for the hash keys' do
18
+ hash.keys.each do |key|
19
+ expect(ts.send(key)).to be_true
20
+ end
21
+ end
22
+
23
+ it 'sets hash value to method' do
24
+ hash.each do |key, val|
25
+ expect(ts.send(key)).to eq val
26
+ end
27
+ end
28
+
29
+ it 'responds to the methods' do
30
+ hash.keys.each do |key|
31
+ expect(ts).to respond_to(key)
32
+ end
33
+ end
34
+
35
+ it 'has a custom #to_s method' do
36
+ expect(ts.to_s).to eq "#<PopCap::TagStruct artist: Artist, date: 1984>"
37
+ end
38
+
39
+ describe 'already defined methods' do
40
+ let(:tags) { {class: 'foo', hash: 'bar', inspect: 'baz'} }
41
+ let(:tag_struct) { TagStruct.new hash }
42
+
43
+ it 'does not set methods defined on class' do
44
+ expect(tag_struct.class).not_to eq 'foo'
45
+ expect(tag_struct.hash).not_to eq 'bar'
46
+ expect(tag_struct.inspect).not_to eq 'baz'
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'support/popcap_spec_helper'
3
+ require 'pop_cap/taggable'
4
+
5
+ module PopCap
6
+ describe Taggable do
7
+ class SomeClass
8
+ include Taggable
9
+ def raw_tags
10
+ PopCapSpecHelper.raw_tags
11
+ end
12
+ end
13
+
14
+ let(:sc) { SomeClass.new }
15
+
16
+ it 'has #raw_tags' do
17
+ expect(sc).to respond_to(:raw_tags)
18
+ end
19
+
20
+ context '#to_hash' do
21
+ it 'builds a sanitized hash from FFmpeg raw_tags' do
22
+ expect(sc.to_hash).to eq PopCapSpecHelper.to_hash
23
+ end
24
+
25
+ it 'is memoized' do
26
+ sc.to_hash
27
+ expect(sc.instance_variable_get('@hash')).
28
+ to eq PopCapSpecHelper.to_hash
29
+ end
30
+ end
31
+
32
+ context '#tags' do
33
+ it 'builds a tag structure of from a hash' do
34
+ expect(sc.tags.album).to eq PopCapSpecHelper.tags.album
35
+ expect(sc.tags.artist).to eq PopCapSpecHelper.tags.artist
36
+ expect(sc.tags.bit_rate).to eq PopCapSpecHelper.tags.bit_rate
37
+ expect(sc.tags.date).to eq PopCapSpecHelper.tags.date
38
+ expect(sc.tags.duration).to eq PopCapSpecHelper.tags.duration
39
+ expect(sc.tags.filename).to eq PopCapSpecHelper.tags.filename
40
+ expect(sc.tags.filesize).to eq PopCapSpecHelper.tags.filesize
41
+ expect(sc.tags.format_name).to eq PopCapSpecHelper.tags.format_name
42
+ expect(sc.tags.genre).to eq PopCapSpecHelper.tags.genre
43
+ expect(sc.tags.title).to eq PopCapSpecHelper.tags.title
44
+ expect(sc.tags.track).to eq PopCapSpecHelper.tags.track
45
+ end
46
+
47
+ it 'is memoized' do
48
+ sc.tags
49
+ expect(sc.instance_variable_get('@tags')).to be_true
50
+ end
51
+ end
52
+
53
+ context '#reload!' do
54
+ it 'sets instance variables to nil' do
55
+ %w(@lined @hash @tags).each do |instance|
56
+ sc.reload!
57
+ expect(sc.instance_variable_get(instance)).to be_nil
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ require 'reek/spec'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.start
5
+
6
+ RSpec.configure do
7
+ include Reek::Spec
8
+ treat_symbols_as_metadata_keys_with_true_values = true
9
+ run_all_when_everything_filtered = true
10
+ order = 'random'
11
+ end
@@ -0,0 +1,86 @@
1
+ require 'fileutils'
2
+ require 'ostruct'
3
+
4
+ module PopCapSpecHelper
5
+ class << self
6
+ def raw_tags
7
+ <<-EOF.gsub(/^\s+/,'')
8
+ [FORMAT]
9
+ filename=#{File.realpath('spec/support/sample.flac')}
10
+ nb_streams=1
11
+ format_name=flac
12
+ format_long_name=raw FLAC
13
+ start_time=N/A
14
+ duration=1.000000
15
+ size=18291
16
+ bit_rate=146328
17
+ TAG:GENRE=Sample Genre
18
+ TAG:track=01
19
+ TAG:ALBUM=Sample Album
20
+ TAG:DATE=2012
21
+ TAG:TITLE=Sample Title
22
+ TAG:ARTIST=Sample Artist
23
+ [/FORMAT]
24
+ EOF
25
+ end
26
+
27
+ def to_hash
28
+ {
29
+ filename: File.realpath('spec/support/sample.flac'),
30
+ nb_streams: '1',
31
+ format_name: 'flac',
32
+ format_long_name: 'raw FLAC',
33
+ start_time: 'N/A',
34
+ duration: '1',
35
+ filesize: '17.9K',
36
+ bit_rate: '146 kb/s',
37
+ genre: 'Sample Genre',
38
+ track: '01',
39
+ album: 'Sample Album',
40
+ date: 2012,
41
+ title: 'Sample Title',
42
+ artist: 'Sample Artist'
43
+ }
44
+ end
45
+
46
+ def tags
47
+ OpenStruct.new(
48
+ {
49
+ filename: File.realpath('spec/support/sample.flac'),
50
+ nb_streams: '1',
51
+ format_name: 'flac',
52
+ format_long_name: 'raw FLAC',
53
+ start_time: 'N/A',
54
+ duration: '1',
55
+ filesize: '17.9K',
56
+ bit_rate: '146 kb/s',
57
+ genre: 'Sample Genre',
58
+ track: '01',
59
+ album: 'Sample Album',
60
+ date: 2012,
61
+ title: 'Sample Title',
62
+ artist: 'Sample Artist' })
63
+ end
64
+
65
+ def remove_converted
66
+ FileUtils.rm_f('spec/support/sample.mp3')
67
+ end
68
+
69
+ def setup
70
+ FileUtils.cp('spec/support/sample.flac', 'spec/support/backup.flac')
71
+ end
72
+
73
+ def teardown
74
+ FileUtils.mv('spec/support/backup.flac', 'spec/support/sample.flac')
75
+ FileUtils.rm_f('spec/support/sample.mp3')
76
+ end
77
+
78
+ def benchmark(&block)
79
+ start = Time.now
80
+ raise(ArgumentError, 'Provide a block.') unless block_given?
81
+ yield
82
+ finish = Time.now
83
+ puts "Time elapsed: #{((finish - stop)*1000).round(3)}ms"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Code Quality' do
4
+ it 'has no code smells' do
5
+ pending 'Enable to test for code smells.'
6
+ expect(Dir['lib/**/*.rb']).not_to reek
7
+ end
8
+ end
Binary file
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: popcap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Culley Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: reek
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ description: Read & write metadata tags, convert audio files to alternate formats,
63
+ manage files on the filesystem.
64
+ email:
65
+ - culley.smith@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - LICENSE
75
+ - README.md
76
+ - lib/pop_cap/audio_file.rb
77
+ - lib/pop_cap/commander.rb
78
+ - lib/pop_cap/converter.rb
79
+ - lib/pop_cap/ffmpeg.rb
80
+ - lib/pop_cap/fileable.rb
81
+ - lib/pop_cap/formatters.rb
82
+ - lib/pop_cap/formatters/bit_rate.rb
83
+ - lib/pop_cap/formatters/date.rb
84
+ - lib/pop_cap/formatters/duration.rb
85
+ - lib/pop_cap/formatters/filesize.rb
86
+ - lib/pop_cap/helper.rb
87
+ - lib/pop_cap/tag_key.rb
88
+ - lib/pop_cap/tag_line.rb
89
+ - lib/pop_cap/tag_struct.rb
90
+ - lib/pop_cap/taggable.rb
91
+ - lib/pop_cap/version.rb
92
+ - lib/popcap.rb
93
+ - popcap.gemspec
94
+ - spec/integration/convert_audio_file_spec.rb
95
+ - spec/integration/read_metatags_spec.rb
96
+ - spec/integration/update_metatags_spec.rb
97
+ - spec/lib/pop_cap/audio_file_spec.rb
98
+ - spec/lib/pop_cap/commander_spec.rb
99
+ - spec/lib/pop_cap/converter_spec.rb
100
+ - spec/lib/pop_cap/ffmpeg_spec.rb
101
+ - spec/lib/pop_cap/fileable_spec.rb
102
+ - spec/lib/pop_cap/formatters/bit_rate_spec.rb
103
+ - spec/lib/pop_cap/formatters/date_spec.rb
104
+ - spec/lib/pop_cap/formatters/duration_spec.rb
105
+ - spec/lib/pop_cap/formatters/filesize_spec.rb
106
+ - spec/lib/pop_cap/formatters_spec.rb
107
+ - spec/lib/pop_cap/helper_spec.rb
108
+ - spec/lib/pop_cap/tag_key_spec.rb
109
+ - spec/lib/pop_cap/tag_line_spec.rb
110
+ - spec/lib/pop_cap/tag_struct_spec.rb
111
+ - spec/lib/pop_cap/taggable_spec.rb
112
+ - spec/spec_helper.rb
113
+ - spec/support/popcap_spec_helper.rb
114
+ - spec/support/reek_spec.rb
115
+ - spec/support/sample.flac
116
+ homepage: http://madstance.com
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: 1.9.3
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.6
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: A library work with audio files on the filesystem .
140
+ test_files:
141
+ - spec/integration/convert_audio_file_spec.rb
142
+ - spec/integration/read_metatags_spec.rb
143
+ - spec/integration/update_metatags_spec.rb
144
+ - spec/lib/pop_cap/audio_file_spec.rb
145
+ - spec/lib/pop_cap/commander_spec.rb
146
+ - spec/lib/pop_cap/converter_spec.rb
147
+ - spec/lib/pop_cap/ffmpeg_spec.rb
148
+ - spec/lib/pop_cap/fileable_spec.rb
149
+ - spec/lib/pop_cap/formatters/bit_rate_spec.rb
150
+ - spec/lib/pop_cap/formatters/date_spec.rb
151
+ - spec/lib/pop_cap/formatters/duration_spec.rb
152
+ - spec/lib/pop_cap/formatters/filesize_spec.rb
153
+ - spec/lib/pop_cap/formatters_spec.rb
154
+ - spec/lib/pop_cap/helper_spec.rb
155
+ - spec/lib/pop_cap/tag_key_spec.rb
156
+ - spec/lib/pop_cap/tag_line_spec.rb
157
+ - spec/lib/pop_cap/tag_struct_spec.rb
158
+ - spec/lib/pop_cap/taggable_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/popcap_spec_helper.rb
161
+ - spec/support/reek_spec.rb
162
+ - spec/support/sample.flac
163
+ has_rdoc: