musk 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6fbabb4893fc5a6bd0f19518e3a907315924c47
4
- data.tar.gz: 9c3aa75d246f6631336e22d0fef746fd75fe1136
3
+ metadata.gz: b1609e780b7c7837ccd4b98100a6e350261f2ebd
4
+ data.tar.gz: d4cc00ca5b1fe8353cda02ade420cb22a0f0d9bb
5
5
  SHA512:
6
- metadata.gz: e83faf0aefe688bbcd451aa9473e4c4a2f4d5b709db75a4207ecaa93d64d89d0d2cb7d4c9751ba9834af52da3266a7bd726d2b6e50ca01cf9f6429b900001ef7
7
- data.tar.gz: d9f5db98079f587d2c5c39ba6132fc47f48d5fc14c2e59f05febd30112a6a2449a0b34627a62a90a5c818861d080c350edd2f0bb702677ecac31f12fd740d65b
6
+ metadata.gz: 53c425a51d2fde4f633dfbee9133a6754364d7025ee506a44803b75eed93b64ba2715f6078e361fa67d8e4128af1e1ecc059a86e4a02b7bd29163e96d4100ba1
7
+ data.tar.gz: 707e0862f0fa78c0e0c80452943578959a90eea99de746abd645a4ae3cbd5c8c06f301d6625ed8c37c83ed5e942cf78bd5faeb86688d735a11b4138a05dd24a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- musk (0.1.5)
4
+ musk (0.1.6)
5
5
  gli (~> 2.9)
6
6
  taglib-ruby (~> 0.6)
7
7
 
@@ -10,19 +10,39 @@ module Musk
10
10
  end
11
11
 
12
12
  def position
13
- "#{position_number}/#{positions_count}"
13
+ "#{number}/#{number_of}"
14
14
  end
15
15
 
16
- [:position_number, :positions_count, :year, :comment].each do |method|
17
- define_method(method) do
18
- [nil, 0, "0"].include?(@track.send(method)) ? "-" : @track.send(method)
19
- end
16
+ def number
17
+ [nil, 0, "0"].include?(@track.number) ? "-" : @track.number
20
18
  end
21
19
 
22
- [:title, :artist, :release, :genre].each do |method|
23
- define_method(method) do
24
- @track.send(method) or "-"
25
- end
20
+ def number_of
21
+ [nil, 0, "0"].include?(@track.number_of) ? "-" : @track.number_of
22
+ end
23
+
24
+ def year
25
+ [nil, 0, "0"].include?(@track.year) ? "-" : @track.year
26
+ end
27
+
28
+ def comment
29
+ [nil, 0, "0"].include?(@track.comment) ? "-" : @track.comment
30
+ end
31
+
32
+ def title
33
+ @track.title or "-"
34
+ end
35
+
36
+ def artist
37
+ @track.artist or "-"
38
+ end
39
+
40
+ def release
41
+ @track.release or "-"
42
+ end
43
+
44
+ def genre
45
+ @track.genre or "-"
26
46
  end
27
47
  end
28
48
  end
data/lib/musk/track.rb CHANGED
@@ -4,8 +4,8 @@ module Musk
4
4
  :loadpath,
5
5
  :fullpath,
6
6
  :title,
7
- :position_number,
8
- :positions_count,
7
+ :number,
8
+ :number_of,
9
9
  :artist,
10
10
  :release,
11
11
  :genre,
@@ -11,13 +11,13 @@ module Musk
11
11
  end
12
12
 
13
13
  def load!
14
- verify_tracks!
15
- create_tracks!
14
+ verify_path!
15
+ create_tracks
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def verify_tracks!
20
+ def verify_path!
21
21
  unless @path and @path.length > 0
22
22
  raise "Undefined path to a file or files"
23
23
  end
@@ -31,29 +31,42 @@ module Musk
31
31
  end
32
32
  end
33
33
 
34
- def create_tracks!
35
- path = File.expand_path(@path)
36
- loadpath = "#{File.file?(path) ? File.dirname(path) : path}#{File::SEPARATOR}"
37
- deeppath = File.file?(path) ? path : File.join(path, "**", "*.mp3")
38
- Dir[deeppath].map do |fullpath|
39
- track = Musk::Track.new
40
- track.loadpath = loadpath
41
- track.fullpath = fullpath
42
- TagLib::MPEG::File.open(fullpath) do |file|
43
- tag = file.id3v2_tag
44
- if tag.frame_list("TRCK").first
45
- number, count = tag.frame_list("TRCK").first.to_s.split("/")
46
- track.position_number = number.to_i
47
- track.positions_count = count.to_i
48
- end
49
- track.title = tag.title
50
- track.artist = tag.artist
51
- track.release = tag.album
52
- track.genre = tag.genre
53
- track.year = tag.year
54
- track.comment = tag.comment
34
+ def fullpath
35
+ @fullpath ||= File.expand_path(@path)
36
+ end
37
+
38
+ def basepath
39
+ @basepath ||= File.dirname(fullpath)
40
+ end
41
+
42
+ def loadpath
43
+ @loadpath ||= "#{File.file?(fullpath) ? basepath : fullpath}#{File::SEPARATOR}"
44
+ end
45
+
46
+ def deeppath
47
+ @deeppath ||= File.file?(fullpath) ? fullpath : File.join(fullpath, "**", "*.mp3")
48
+ end
49
+
50
+ def create_tracks
51
+ Dir[deeppath].map do |filepath|
52
+ TagLib::MPEG::File.open(filepath) do |file|
53
+ create_track(filepath, file.id3v2_tag)
55
54
  end
56
- track
55
+ end
56
+ end
57
+
58
+ def create_track(filepath, tag)
59
+ Musk::Track.new.tap do |track|
60
+ track.loadpath = loadpath
61
+ track.fullpath = filepath
62
+ track.number = tag.frame_list("TRCK").first.to_s.split("/").first
63
+ track.number_of = tag.frame_list("TRCK").first.to_s.split("/").last
64
+ track.title = tag.title.to_s
65
+ track.artist = tag.artist.to_s
66
+ track.release = tag.album.to_s
67
+ track.genre = tag.genre.to_s
68
+ track.year = tag.year.to_s
69
+ track.comment = tag.comment.to_s
57
70
  end
58
71
  end
59
72
  end
data/lib/musk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Musk
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -14,20 +14,20 @@ describe Musk::Decorator::PrintableTrack do
14
14
  end
15
15
 
16
16
  describe "#position" do
17
- it "should return '{position_number}/{positions_count}'" do
17
+ it "should return '{number}/{number_of}'" do
18
18
  track = described_class.new(build(:track))
19
- allow(track).to receive(:position_number).and_return(1)
20
- allow(track).to receive(:positions_count).and_return(2)
19
+ allow(track).to receive(:number).and_return(1)
20
+ allow(track).to receive(:number_of).and_return(2)
21
21
  position = track.position
22
22
  position.should eq("1/2")
23
- expect(track).to have_received(:position_number)
24
- expect(track).to have_received(:positions_count)
23
+ expect(track).to have_received(:number)
24
+ expect(track).to have_received(:number_of)
25
25
  end
26
26
  end
27
27
 
28
28
  it_should_behave_like "the track decorator with zeroable attributes", [
29
- :position_number,
30
- :positions_count,
29
+ :number,
30
+ :number_of,
31
31
  :comment,
32
32
  :year,
33
33
  ]
@@ -7,10 +7,10 @@ describe Musk::Track do
7
7
  it { should respond_to(:fullpath=) }
8
8
  it { should respond_to(:title) }
9
9
  it { should respond_to(:title=) }
10
- it { should respond_to(:position_number) }
11
- it { should respond_to(:position_number=) }
12
- it { should respond_to(:positions_count) }
13
- it { should respond_to(:positions_count=) }
10
+ it { should respond_to(:number) }
11
+ it { should respond_to(:number=) }
12
+ it { should respond_to(:number_of) }
13
+ it { should respond_to(:number_of=) }
14
14
  it { should respond_to(:artist) }
15
15
  it { should respond_to(:artist=) }
16
16
  it { should respond_to(:release) }
@@ -6,12 +6,12 @@ FactoryGirl.define do
6
6
  loadpath ENV["MUSK_TRACKS_PATH"]
7
7
  fullpath File.join(ENV["MUSK_TRACKS_PATH"], "bonobo/jets.mp3")
8
8
  title "Jets"
9
- position_number 6
10
- positions_count 13
9
+ number "6"
10
+ number_of "13"
11
11
  artist "Bonobo"
12
12
  release "The North Borders"
13
13
  genre "Electronic"
14
- year 2013
14
+ year "2013"
15
15
 
16
16
  trait :loaded do
17
17
  comment "0"
@@ -22,12 +22,12 @@ FactoryGirl.define do
22
22
  loadpath ENV["MUSK_TRACKS_PATH"]
23
23
  fullpath File.join(ENV["MUSK_TRACKS_PATH"], "emancipator/kamakura.mp3")
24
24
  title "Kamakura"
25
- position_number 4
26
- positions_count 14
25
+ number "4"
26
+ number_of "14"
27
27
  artist "Emancipator"
28
28
  release "Safe In The Steep Cliffs"
29
29
  genre "Electronic"
30
- year 2010
30
+ year "2010"
31
31
 
32
32
  trait :loaded do
33
33
  comment "0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Pempel