muzak 0.3.6 → 0.3.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/muzak.rb +1 -1
  3. data/lib/muzak/index.rb +20 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 809d9fd5e4afee2f04affc8214c4f7c5a7980aa7
4
- data.tar.gz: bacfe904636a5b9614082341d7a3d6b7358c691e
3
+ metadata.gz: 77d8a106e1b6479194813a854372b1623f3bac7b
4
+ data.tar.gz: 4eb72201a9378ba5ee92c43668009ab314c1e1ff
5
5
  SHA512:
6
- metadata.gz: 4afbbbf920fb553fbdd6cc19dc443a02c2425b5d919e735c7f8bd6988f9a2f9630fe5cf7f049e1f361633020b9e7c2864107d1b9dc5f474c7f0b0ea3e334d515
7
- data.tar.gz: e99922aa6b052e5aa4799040b1f58cab6fc76617e5b199931f2983b06510a2c6d16ffd1823884a1cc5cf22d950bc5bcee54aea31c803ec9ecc72e8c1a8e1abc9
6
+ metadata.gz: e94f921353d774220411452b8ecd4a49003792d0f0a7a3a96d8cbda3d6d92518e6b50a2c46d1afaf8a7050136ffadc0a069c08857ee0e717bc589e9613262f5d
7
+ data.tar.gz: 8bb4da0e3c69ad6e319b46db29a21031aec4d55ce6aef2b4ae33dca91dd4d44c7ec488f151b382485a29da7cdfa1e7be96fb1dca5135c5602c0412e3d6a397c9
data/lib/muzak.rb CHANGED
@@ -12,5 +12,5 @@ require_relative "muzak/instance"
12
12
  # The primary namespace for muzak.
13
13
  module Muzak
14
14
  # Muzak's current version
15
- VERSION = "0.3.6".freeze
15
+ VERSION = "0.3.7".freeze
16
16
  end
data/lib/muzak/index.rb CHANGED
@@ -23,6 +23,15 @@ module Muzak
23
23
  debug "loading index from '#{Config::INDEX_FILE}'..."
24
24
 
25
25
  @hash = Marshal.load(File.read file)
26
+
27
+ # create some frequently accessed collections
28
+ @all_albums = @hash["artists"].map { |_, a| a["albums"] }.flatten
29
+
30
+ if deep?
31
+ @all_deep_songs = @all_albums.map { |aa| aa.map { |_, a| a["deep-songs"] } }.flatten
32
+ else
33
+ @all_songs = @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
34
+ end
26
35
  end
27
36
 
28
37
  # @return [Boolean] whether or not the current index is deep
@@ -61,6 +70,17 @@ module Muzak
61
70
  end
62
71
  end
63
72
 
73
+ # @return [Array<Song>] a list of all Song objects in the index
74
+ # @note This method **requires** a deep index.
75
+ def songs
76
+ unless deep?
77
+ danger "tried to call a deep-index-only method with a shallow index"
78
+ return []
79
+ end
80
+
81
+ @all_deep_songs
82
+ end
83
+
64
84
  # @return [Array<String>] a list of all albums in the index
65
85
  # @note albums with the same name will appear, but can't be disambiguated
66
86
  # from here
@@ -90,13 +110,9 @@ module Muzak
90
110
  # @param count [Integer] the number of random songs to return
91
111
  # @return [Array<Song>] an array of randomly chosen songs
92
112
  def jukebox(count = 50)
93
- @all_albums ||= @hash["artists"].map { |_, a| a["albums"] }.flatten
94
-
95
113
  if deep?
96
- @all_deep_songs ||= @all_albums.map { |aa| aa.map { |_, a| a["deep-songs"] } }.flatten
97
114
  @all_deep_songs.sample(count)
98
115
  else
99
- @all_songs ||= @all_albums.map { |aa| aa.map { |_, a| a["songs"] } }.flatten
100
116
  @all_songs.sample(count).map { |s| Song.new(s) }
101
117
  end
102
118
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-29 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: taglib-ruby