musk 0.0.3 → 0.0.4

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: dbe21ecab6424d26fc0bad44e87410d0ce7bfe30
4
- data.tar.gz: e1acde8199b48808e9756371812bcf8752f3dfd5
3
+ metadata.gz: de4f097d74a73c706373689095573eede025a309
4
+ data.tar.gz: 3dfe5fff8e66130a94c826d582456159e75ee8ce
5
5
  SHA512:
6
- metadata.gz: 970e98e097362cf63acc293754583ac067698a2ad053756cf118235ff040ee30c858978637b3d0e41043d328f34ac1ee37d21a63b824b55431c8f90a7ffbfa32
7
- data.tar.gz: 949dfe1b4c97d634f9b9d74095f50e347df8b8fc560e71a8a5d656171dddaa15b6d89379eb0ab6bf08c2e9ced634f26be0331a32554304494ce682deb097cf01
6
+ metadata.gz: 8fbef5b662def26e868f5b81032e90606f3b014a2dcc448b5086f46c014b83b94151b0d8e6da214c04a2348d3a5a4a4016b922f994fb5848eb595e2c4d52d340
7
+ data.tar.gz: 034fb77607002b90a4c8bf10c36a704e0a7bf85762ef37c5019ad2bc077d552b53e50ab337b3a86c95c4ee39e8405839909347c96189271056bc7f70031d7de9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- musk (0.0.3)
4
+ musk (0.0.4)
5
5
  gli (~> 2.9)
6
6
  taglib-ruby (~> 0.6)
7
7
 
data/bin/musk CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "gli"
4
- require "musk/track_loader"
5
- require "musk/track_printer"
4
+ require "musk"
6
5
 
7
6
  extend GLI::App
8
7
 
9
8
  desc "Extract meta-data (tags) from MP3 files"
10
- arg_name "path_to_file or path_to_files"
9
+ arg_name "path_to_files"
11
10
  command :extract do |command|
12
- command.arg_name "format"
11
+ command.arg_name "csv|pretty"
13
12
  command.default_value "pretty"
14
13
  command.flag [:f, :format]
15
14
  command.action do |global_options, options, arguments|
@@ -0,0 +1,23 @@
1
+ module Musk
2
+ module Formatter
3
+ class CSV
4
+ ATTRIBUTES = [
5
+ :path,
6
+ :title,
7
+ :position,
8
+ :artist,
9
+ :album,
10
+ :genre,
11
+ :year,
12
+ :comment,
13
+ ]
14
+
15
+ def self.print(tracks)
16
+ tracks.each do |track|
17
+ track = Musk::Decorator::PrintableTrack.new(track)
18
+ puts ATTRIBUTES.map {|a| track.send(a)}.join(",")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,20 +1,24 @@
1
- require "musk/decorator/printable_track"
2
-
3
1
  module Musk
4
2
  module Formatter
5
3
  class Pretty
4
+ ATTRIBUTES = [
5
+ :path,
6
+ :title,
7
+ :position,
8
+ :artist,
9
+ :album,
10
+ :genre,
11
+ :year,
12
+ :comment,
13
+ ]
14
+
6
15
  def self.print(tracks)
7
16
  tracks.each_with_index do |track, index|
8
- track = Musk::Decorator::PrintableTrack.new(track)
9
17
  puts if index > 0
10
- printf("%-10s%s\n", "Path:", track.path)
11
- printf("%-10s%s\n", "Title:", track.title)
12
- printf("%-10s%s\n", "Position:", track.position)
13
- printf("%-10s%s\n", "Artist:", track.artist)
14
- printf("%-10s%s\n", "Album:", track.album)
15
- printf("%-10s%s\n", "Genre:", track.genre)
16
- printf("%-10s%s\n", "Year:", track.year)
17
- printf("%-10s%s\n", "Comment:", track.comment)
18
+ ATTRIBUTES.map do |attribute|
19
+ track = Musk::Decorator::PrintableTrack.new(track)
20
+ printf("%-10s%s\n", "#{attribute.capitalize}:", track.send(attribute))
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -1,5 +1,4 @@
1
1
  require "taglib"
2
- require "musk/track"
3
2
 
4
3
  module Musk
5
4
  class TrackLoader
@@ -1,11 +1,9 @@
1
- require "musk/formatter/pretty"
2
-
3
1
  module Musk
4
2
  class TrackPrinter
5
3
  def self.print!(format, tracks)
6
4
  case format.to_s.to_sym
7
- when :pretty
8
- Musk::Formatter::Pretty.print(tracks)
5
+ when :csv then Musk::Formatter::CSV.print(tracks)
6
+ when :pretty then Musk::Formatter::Pretty.print(tracks)
9
7
  else
10
8
  raise "Unknown format '#{format}'"
11
9
  end
data/lib/musk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Musk
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/musk.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require "musk/decorator/printable_track"
2
+ require "musk/formatter/csv"
3
+ require "musk/formatter/pretty"
1
4
  require "musk/track"
2
5
  require "musk/track_loader"
3
6
  require "musk/track_printer"
7
+ require "musk/version"
@@ -1,41 +1,43 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "musk extract" do
4
- let(:command) { "bundle exec bin/musk extract" }
5
-
6
4
  context "called without arguments" do
7
5
  it "should fail with the exit code 1" do
8
- stdout, stderr, status = Open3.capture3(command)
6
+ stdout, stderr, status = Open3.capture3("bundle exec bin/musk extract")
9
7
  status.exitstatus.should eq(1)
10
8
  end
11
9
 
12
10
  it "should write an error message to STDERR" do
13
- stdout, stderr, status = Open3.capture3(command)
11
+ stdout, stderr, status = Open3.capture3("bundle exec bin/musk extract")
14
12
  stderr.should_not be_empty
15
13
  end
16
14
  end
17
15
 
18
16
  context "called with 'path_to_tracks'" do
19
- it_should_behave_like "a command to print tracks to STDOUT in the pretty format" do
20
- let(:expected_command) { command }
21
- end
17
+ it_should_behave_like "the extract command with the pretty format"
22
18
  end
23
19
 
24
- context "called with '-f pretty path_to_tracks'" do
25
- it_should_behave_like "a command to print tracks to STDOUT in the pretty format" do
26
- let(:expected_command) { "#{command} -f pretty" }
27
- end
20
+ context "called with 'path_to_tracks -f pretty'" do
21
+ it_should_behave_like "the extract command with the pretty format", "-f pretty"
28
22
  end
29
23
 
30
- context "called with '--format pretty path_to_tracks'" do
31
- it_should_behave_like "a command to print tracks to STDOUT in the pretty format" do
32
- let(:expected_command) { "#{command} --format pretty" }
33
- end
24
+ context "called with 'path_to_tracks --format pretty'" do
25
+ it_should_behave_like "the extract command with the pretty format", "--format pretty"
34
26
  end
35
27
 
36
- context "called with '--format=pretty path_to_tracks'" do
37
- it_should_behave_like "a command to print tracks to STDOUT in the pretty format" do
38
- let(:expected_command) { "#{command} --format=pretty" }
39
- end
28
+ context "called with 'path_to_tracks --format=pretty'" do
29
+ it_should_behave_like "the extract command with the pretty format", "--format=pretty"
30
+ end
31
+
32
+ context "called with 'path_to_tracks -f csv'" do
33
+ it_should_behave_like "the extract command with the csv format", "-f csv"
34
+ end
35
+
36
+ context "called with 'path_to_tracks --format csv'" do
37
+ it_should_behave_like "the extract command with the csv format", "--format csv"
38
+ end
39
+
40
+ context "called with 'path_to_tracks --format=csv'" do
41
+ it_should_behave_like "the extract command with the csv format", "--format=csv"
40
42
  end
41
43
  end
@@ -25,14 +25,14 @@ describe Musk::Decorator::PrintableTrack do
25
25
  end
26
26
  end
27
27
 
28
- it_should_behave_like "a decorator with zeroable attributes", [
28
+ it_should_behave_like "the track decorator with zeroable attributes", [
29
29
  :position_number,
30
30
  :positions_count,
31
31
  :comment,
32
32
  :year,
33
33
  ]
34
34
 
35
- it_should_behave_like "a decorator with nullable attributes", [
35
+ it_should_behave_like "the track decorator with nullable attributes", [
36
36
  :title,
37
37
  :artist,
38
38
  :album,
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Musk::Formatter::CSV do
4
+ describe ".print(tracks)" do
5
+ let(:tracks) do
6
+ [build(:jets_track), build(:kamakura_track)]
7
+ end
8
+
9
+ let(:printable_tracks) do
10
+ tracks.map {|t| Musk::Decorator::PrintableTrack.new(t)}
11
+ end
12
+
13
+ let(:attributes) do
14
+ [:path, :title, :position, :artist, :album, :genre, :year, :comment]
15
+ end
16
+
17
+ let(:stdout) do
18
+ printable_tracks.map do |track|
19
+ attributes.map {|a| track.send(a)}.join(",").concat("\n")
20
+ end.join
21
+ end
22
+
23
+ it "should print tracks to STDOUT in the csv format" do
24
+ capture_stdout { described_class.print(tracks) }.should eq(stdout)
25
+ end
26
+ end
27
+ end
@@ -4,7 +4,15 @@ describe Musk::TrackPrinter do
4
4
  describe ".print!(format, tracks)" do
5
5
  let(:tracks) { build_list(:track, 2) }
6
6
 
7
- context "when format is the pretty format" do
7
+ context "when format == 'csv'" do
8
+ it "should call Musk::Formatter::CSV.print(tracks)" do
9
+ allow(Musk::Formatter::CSV).to receive(:print).with(tracks)
10
+ described_class.print!('csv', tracks)
11
+ expect(Musk::Formatter::CSV).to have_received(:print).with(tracks)
12
+ end
13
+ end
14
+
15
+ context "when format == 'pretty'" do
8
16
  it "should call Musk::Formatter::Pretty.print(tracks)" do
9
17
  allow(Musk::Formatter::Pretty).to receive(:print).with(tracks)
10
18
  described_class.print!('pretty', tracks)
@@ -12,7 +20,7 @@ describe Musk::TrackPrinter do
12
20
  end
13
21
  end
14
22
 
15
- context "when format is an unsupported format" do
23
+ context "else" do
16
24
  it "should raise \"Unknown format '{format}'\"" do
17
25
  error = "Unknown format 'unsupported'"
18
26
  expect { described_class.print!('unsupported', tracks) }.to raise_error(error)
@@ -0,0 +1,11 @@
1
+ shared_examples "the extract command with the csv format" do |options|
2
+ let(:command) { "bundle exec bin/musk extract" }
3
+
4
+ it "should print tracks to STDOUT via Musk::Formatter::CSV" do
5
+ path = ENV["MUSK_TRACKS_PATH"]
6
+ tracks = Musk::TrackLoader.load!(path)
7
+ stdout, stderr, status = Open3.capture3("#{command} #{options} #{path}")
8
+ stdout.should eq(capture_stdout {Musk::Formatter::CSV.print(tracks)})
9
+ status.exitstatus.should eq(0)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples "the extract command with the pretty format" do |options|
2
+ let(:command) { "bundle exec bin/musk extract" }
3
+
4
+ it "should print tracks to STDOUT via Musk::Formatter::Pretty" do
5
+ path = ENV["MUSK_TRACKS_PATH"]
6
+ tracks = Musk::TrackLoader.load!(path)
7
+ stdout, stderr, status = Open3.capture3("#{command} #{options} #{path}")
8
+ stdout.should eq(capture_stdout {Musk::Formatter::Pretty.print(tracks)})
9
+ status.exitstatus.should eq(0)
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
- shared_examples "a decorator with nullable attributes" do |attributes|
2
- subject { Musk::Decorator::PrintableTrack }
1
+ shared_examples "the track decorator with nullable attributes" do |attributes|
2
+ let(:decorator) { Musk::Decorator::PrintableTrack }
3
3
 
4
4
  attributes.each do |attribute|
5
5
  describe "##{attribute}" do
@@ -7,7 +7,7 @@ shared_examples "a decorator with nullable attributes" do |attributes|
7
7
  it "should return '-'" do
8
8
  track = build(:track)
9
9
  allow(track).to receive(attribute).and_return(nil)
10
- subject.new(track).send(attribute).should eq("-")
10
+ decorator.new(track).send(attribute).should eq("-")
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ shared_examples "a decorator with nullable attributes" do |attributes|
15
15
  it "should return track.#{attribute}" do
16
16
  track = build(:track)
17
17
  allow(track).to receive(attribute).and_return("VaLuE")
18
- subject.new(track).send(attribute).should eq("VaLuE")
18
+ decorator.new(track).send(attribute).should eq("VaLuE")
19
19
  end
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
- shared_examples "a decorator with zeroable attributes" do |attributes|
2
- subject { Musk::Decorator::PrintableTrack }
1
+ shared_examples "the track decorator with zeroable attributes" do |attributes|
2
+ let(:decorator) { Musk::Decorator::PrintableTrack }
3
3
 
4
4
  attributes.each do |attribute|
5
5
  describe "##{attribute}" do
@@ -7,7 +7,7 @@ shared_examples "a decorator with zeroable attributes" do |attributes|
7
7
  it "should return '-'" do
8
8
  track = build(:track)
9
9
  allow(track).to receive(attribute).and_return(nil)
10
- subject.new(track).send(attribute).should eq("-")
10
+ decorator.new(track).send(attribute).should eq("-")
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ shared_examples "a decorator with zeroable attributes" do |attributes|
15
15
  it "should return '-'" do
16
16
  track = build(:track)
17
17
  allow(track).to receive(attribute).and_return(0)
18
- subject.new(track).send(attribute).should eq("-")
18
+ decorator.new(track).send(attribute).should eq("-")
19
19
  end
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ shared_examples "a decorator with zeroable attributes" do |attributes|
23
23
  it "should return '-'" do
24
24
  track = build(:track)
25
25
  allow(track).to receive(attribute).and_return("0")
26
- subject.new(track).send(attribute).should eq("-")
26
+ decorator.new(track).send(attribute).should eq("-")
27
27
  end
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ shared_examples "a decorator with zeroable attributes" do |attributes|
31
31
  it "should return track.#{attribute}" do
32
32
  track = build(:track)
33
33
  allow(track).to receive(attribute).and_return("VaLuE")
34
- subject.new(track).send(attribute).should eq("VaLuE")
34
+ decorator.new(track).send(attribute).should eq("VaLuE")
35
35
  end
36
36
  end
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Pempel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -138,6 +138,7 @@ files:
138
138
  - bin/musk
139
139
  - lib/musk.rb
140
140
  - lib/musk/decorator/printable_track.rb
141
+ - lib/musk/formatter/csv.rb
141
142
  - lib/musk/formatter/pretty.rb
142
143
  - lib/musk/track.rb
143
144
  - lib/musk/track_loader.rb
@@ -146,14 +147,16 @@ files:
146
147
  - musk.gemspec
147
148
  - spec/bin/musk_spec.rb
148
149
  - spec/lib/musk/decorator/printable_track_spec.rb
150
+ - spec/lib/musk/formatter/csv_spec.rb
149
151
  - spec/lib/musk/formatter/pretty_spec.rb
150
152
  - spec/lib/musk/track_loader_spec.rb
151
153
  - spec/lib/musk/track_printer_spec.rb
152
154
  - spec/lib/musk/track_spec.rb
153
155
  - spec/spec_helper.rb
154
- - spec/support/examples/command_to_print_tracks_to_stdout_in_pretty_format_example.rb
155
- - spec/support/examples/decorator_with_nullable_attributes_example.rb
156
- - spec/support/examples/decorator_with_zeroable_attributes_example.rb
156
+ - spec/support/examples/extract_command_with_csv_format_example.rb
157
+ - spec/support/examples/extract_command_with_pretty_format_example.rb
158
+ - spec/support/examples/track_decorator_with_nullable_attributes_example.rb
159
+ - spec/support/examples/track_decorator_with_zeroable_attributes_example.rb
157
160
  - spec/support/factories/tracks.rb
158
161
  - spec/support/helpers/capture_stdout_helper.rb
159
162
  - spec/support/matchers/be_tracks_matcher.rb
@@ -186,14 +189,16 @@ summary: Your music with the demonic scent of musk
186
189
  test_files:
187
190
  - spec/bin/musk_spec.rb
188
191
  - spec/lib/musk/decorator/printable_track_spec.rb
192
+ - spec/lib/musk/formatter/csv_spec.rb
189
193
  - spec/lib/musk/formatter/pretty_spec.rb
190
194
  - spec/lib/musk/track_loader_spec.rb
191
195
  - spec/lib/musk/track_printer_spec.rb
192
196
  - spec/lib/musk/track_spec.rb
193
197
  - spec/spec_helper.rb
194
- - spec/support/examples/command_to_print_tracks_to_stdout_in_pretty_format_example.rb
195
- - spec/support/examples/decorator_with_nullable_attributes_example.rb
196
- - spec/support/examples/decorator_with_zeroable_attributes_example.rb
198
+ - spec/support/examples/extract_command_with_csv_format_example.rb
199
+ - spec/support/examples/extract_command_with_pretty_format_example.rb
200
+ - spec/support/examples/track_decorator_with_nullable_attributes_example.rb
201
+ - spec/support/examples/track_decorator_with_zeroable_attributes_example.rb
197
202
  - spec/support/factories/tracks.rb
198
203
  - spec/support/helpers/capture_stdout_helper.rb
199
204
  - spec/support/matchers/be_tracks_matcher.rb
@@ -1,9 +0,0 @@
1
- shared_examples "a command to print tracks to STDOUT in the pretty format" do
2
- it "should print tracks to STDOUT via Musk::Formatter::Pretty" do
3
- path = ENV["MUSK_TRACKS_PATH"]
4
- tracks = Musk::TrackLoader.load!(path)
5
- stdout, stderr, status = Open3.capture3("#{expected_command} #{path}")
6
- stdout.should eq(capture_stdout { Musk::Formatter::Pretty.print(tracks) })
7
- status.exitstatus.should eq(0)
8
- end
9
- end