musk 0.1.7 → 0.1.8

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: 5f0adaae714ee1cae505776968e98e731e9d505b
4
- data.tar.gz: 46c6906ba26318a60a629af3546024974ee28c08
3
+ metadata.gz: 6d3cfe8d2f4b025504f856f58912b4dbb2dc806b
4
+ data.tar.gz: fef5e17b70ea89e296e4734dab2ed4c1c22833e1
5
5
  SHA512:
6
- metadata.gz: 0e26c7088e208a31dfac5954d301cbc41e83e3afba7a560a063817d72c5211f31db8c4269ebd8875ff315529a79a0ecbcd72e278febb1e12950c35ef6b02c8e9
7
- data.tar.gz: 089ba815b88791687069a5c3f7475bbd13fe408f4fec1af15abb20c7f6b6ea97480c7d622134ab66663db7838401e0375c3df29d27a4f1c8753ce78cb63a3e24
6
+ metadata.gz: 06954d894d0a0c26b3b7db4bd502e9ec458e4d431ca8fbc90302123afd60e0348af85a98c6fc6e1d82fd91b4e57b7352069ee68b05a2038e6566d01dc8bb44fe
7
+ data.tar.gz: ba57a7874101c727a5ecc5195fcfc2f6cc94556f4931aa272bdffb235134e937f2fda3727299aad4741c451555c832e721f6eb116bb46d2764af92448162d1d5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- musk (0.1.7)
4
+ musk (0.1.8)
5
5
  gli (~> 2.9)
6
6
  taglib-ruby (~> 0.6)
7
7
 
@@ -3,6 +3,7 @@ require "musk/formatter/base"
3
3
  require "musk/formatter/csv"
4
4
  require "musk/formatter/pretty"
5
5
  require "musk/track"
6
+ require "musk/track_adapter"
6
7
  require "musk/track_loader"
7
8
  require "musk/track_printer"
8
9
  require "musk/version"
@@ -15,14 +15,12 @@ module Musk
15
15
 
16
16
  attr_accessor *ATTRIBUTES
17
17
 
18
- def attributes
19
- Hash[ATTRIBUTES.map { |a| [a, send("#{a}")] }]
18
+ def initialize(attributes = {})
19
+ attributes.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
20
20
  end
21
21
 
22
- def attributes=(hash)
23
- hash.each do |key, value|
24
- send("#{key}=", value) if respond_to?("#{key}=")
25
- end
22
+ def attributes
23
+ Hash[ATTRIBUTES.map { |a| [a, send("#{a}")] }]
26
24
  end
27
25
  end
28
26
  end
@@ -0,0 +1,56 @@
1
+ module Musk
2
+ class TrackAdapter
3
+ def self.adapt(tag)
4
+ new(tag).adapt
5
+ end
6
+
7
+ def initialize(tag)
8
+ @tag = tag
9
+ end
10
+
11
+ def adapt
12
+ Musk::Track.new(attributes)
13
+ end
14
+
15
+ private
16
+
17
+ def attributes
18
+ Musk::Track::ATTRIBUTES.inject({}) do |hash, attribute|
19
+ hash[attribute] = send(attribute) if respond_to?(attribute, true)
20
+ hash
21
+ end
22
+ end
23
+
24
+ def number
25
+ @tag.frame_list("TRCK").first.to_s.split("/").first
26
+ end
27
+
28
+ def number_of
29
+ @tag.frame_list("TRCK").first.to_s.split("/").last
30
+ end
31
+
32
+ def title
33
+ @tag.title
34
+ end
35
+
36
+ def artist
37
+ @tag.artist
38
+ end
39
+
40
+ def release
41
+ @tag.album
42
+ end
43
+
44
+ def genre
45
+ @tag.genre
46
+ end
47
+
48
+ def year
49
+ @tag.year.to_s
50
+ end
51
+
52
+ def comment
53
+ @tag.comment
54
+ end
55
+ end
56
+ end
@@ -31,45 +31,31 @@ module Musk
31
31
  end
32
32
  end
33
33
 
34
- def fullpath
35
- @fullpath ||= File.expand_path(@path)
34
+ def create_tracks
35
+ Dir[deeppath].map do |filepath|
36
+ TagLib::MPEG::File.open(filepath) do |file|
37
+ Musk::TrackAdapter.adapt(file.id3v2_tag).tap do |track|
38
+ track.loadpath = loadpath
39
+ track.fullpath = filepath
40
+ end
41
+ end
42
+ end
36
43
  end
37
44
 
38
- def basepath
39
- @basepath ||= File.dirname(fullpath)
45
+ def deeppath
46
+ @deeppath ||= File.file?(fullpath) ? fullpath : File.join(fullpath, "**", "*.mp3")
40
47
  end
41
48
 
42
49
  def loadpath
43
50
  @loadpath ||= "#{File.file?(fullpath) ? basepath : fullpath}#{File::SEPARATOR}"
44
51
  end
45
52
 
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)
54
- end
55
- end
53
+ def basepath
54
+ @basepath ||= File.dirname(fullpath)
56
55
  end
57
56
 
58
- def create_track(filepath, tag)
59
- Musk::Track.new.tap do |track|
60
- track.attributes = {
61
- loadpath: loadpath,
62
- fullpath: filepath,
63
- number: tag.frame_list("TRCK").first.to_s.split("/").first,
64
- number_of: tag.frame_list("TRCK").first.to_s.split("/").last,
65
- title: tag.title,
66
- artist: tag.artist,
67
- release: tag.album,
68
- genre: tag.genre,
69
- year: tag.year.to_s,
70
- comment: tag.comment,
71
- }
72
- end
57
+ def fullpath
58
+ @fullpath ||= File.expand_path(@path)
73
59
  end
74
60
  end
75
61
  end
@@ -1,3 +1,3 @@
1
1
  module Musk
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Pempel
@@ -59,6 +59,7 @@ files:
59
59
  - lib/musk/formatter/csv.rb
60
60
  - lib/musk/formatter/pretty.rb
61
61
  - lib/musk/track.rb
62
+ - lib/musk/track_adapter.rb
62
63
  - lib/musk/track_loader.rb
63
64
  - lib/musk/track_printer.rb
64
65
  - lib/musk/version.rb