Class: Hearken::Library

Inherits:
Object
  • Object
show all
Includes:
Debug, Paths
Defined in:
lib/hearken/library.rb

Constant Summary collapse

FILE_FIELDS =
%w{path timestamp}
TAG_FIELDS =
%w{album track title artist time date albumartist puid mbartistid mbalbumid mbalbumartistid asin}
FIELDS =
FILE_FIELDS + TAG_FIELDS

Instance Attribute Summary collapse

Attributes included from Paths

#base_path, #index_path, #preferences_path, #queue_path

Instance Method Summary collapse

Methods included from Debug

#debug, #pause

Methods included from Paths

#create_paths, #in_base_dir, #in_queue_dir

Constructor Details

#initialize(preferences) ⇒ Library

Returns a new instance of Library.



14
15
16
# File 'lib/hearken/library.rb', line 14

def initialize preferences
  create_paths
end

Instance Attribute Details

#tracksObject (readonly)

Returns the value of attribute tracks.



12
13
14
# File 'lib/hearken/library.rb', line 12

def tracks
  @tracks
end

Instance Method Details

#countObject



18
19
20
# File 'lib/hearken/library.rb', line 18

def count
  @tracks.count
end

#reloadObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hearken/library.rb', line 30

def reload
  @tracks = []
  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 if File.exist? index_path
end

#row(id) ⇒ Object



22
23
24
# File 'lib/hearken/library.rb', line 22

def row id
  @tracks[id]
end

#with_track(id) {|@tracks[id]| ... } ⇒ Object

Yields:



26
27
28
# File 'lib/hearken/library.rb', line 26

def with_track id
  yield @tracks[id]
end