Class: Hearken::Library
- Inherits:
-
Object
- Object
- Hearken::Library
- 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
-
#tracks ⇒ Object
readonly
Returns the value of attribute tracks.
Attributes included from Paths
#base_path, #index_path, #preferences_path, #queue_path
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(preferences) ⇒ Library
constructor
A new instance of Library.
- #reload ⇒ Object
- #row(id) ⇒ Object
- #with_track(id) {|@tracks[id]| ... } ⇒ Object
Methods included from Debug
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
#tracks ⇒ Object (readonly)
Returns the value of attribute tracks.
12 13 14 |
# File 'lib/hearken/library.rb', line 12 def tracks @tracks end |
Instance Method Details
#count ⇒ Object
18 19 20 |
# File 'lib/hearken/library.rb', line 18 def count @tracks.count end |
#reload ⇒ Object
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
26 27 28 |
# File 'lib/hearken/library.rb', line 26 def with_track id yield @tracks[id] end |