Class: Hearken::Library
Constant Summary
collapse
- FILE_FIELDS =
%w[path timestamp].freeze
- TAG_FIELDS =
%w[album track title artist time date albumartist puid mbartistid mbalbumid mbalbumartistid asin].freeze
- FIELDS =
FILE_FIELDS + TAG_FIELDS
Instance Attribute Summary collapse
Attributes included from Paths
#base_path, #index_path
Instance Method Summary
collapse
Methods included from Debug
#debug, #pause
Methods included from Paths
#create_paths, #in_base_dir
Constructor Details
Returns a new instance of Library.
18
19
20
21
22
|
# File 'lib/hearken/library.rb', line 18
def initialize
@tracks = []
create_paths
reload
end
|
Instance Attribute Details
#tracks ⇒ Object
Returns the value of attribute tracks.
16
17
18
|
# File 'lib/hearken/library.rb', line 16
def tracks
@tracks
end
|
Instance Method Details
#count ⇒ Object
24
25
26
|
# File 'lib/hearken/library.rb', line 24
def count
@tracks.count
end
|
#reload ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/hearken/library.rb', line 36
def reload
return unless File.exist?(index_path)
File.open index_path do |file|
id = 0
while (line = file.gets)
row = line.chomp.split "<->"
track = Hearken::Track.new id
FIELDS.each { |field| track.send "#{field}=", row.shift }
@tracks << track
id += 1
end
end
end
|
#row(id) ⇒ Object
28
29
30
|
# File 'lib/hearken/library.rb', line 28
def row(id)
@tracks[id]
end
|
#with_track(id) {|| ... } ⇒ Object
32
33
34
|
# File 'lib/hearken/library.rb', line 32
def with_track(id)
yield @tracks[id]
end
|