Class: MusicLibrary
- Inherits:
-
Object
- Object
- MusicLibrary
- Defined in:
- lib/itc/musiclib.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
Instance Method Summary collapse
-
#initialize(file) ⇒ MusicLibrary
constructor
A new instance of MusicLibrary.
- #parse_xml ⇒ Object
Constructor Details
#initialize(file) ⇒ MusicLibrary
Returns a new instance of MusicLibrary.
8 9 10 11 12 13 |
# File 'lib/itc/musiclib.rb', line 8 def initialize(file) @file = file @tracks = [] parse_xml end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/itc/musiclib.rb', line 6 def file @file end |
#tracks ⇒ Object
Returns the value of attribute tracks.
6 7 8 |
# File 'lib/itc/musiclib.rb', line 6 def tracks @tracks end |
Instance Method Details
#parse_xml ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/itc/musiclib.rb', line 15 def parse_xml entities = HTMLEntities.new in_tracks = false track = {} IO.foreach(File.(@file)) do |line| line = line.force_encoding("UTF-8") if line =~ /^\t<key>Tracks<\/key>$/ in_tracks = true next end if in_tracks then if line =~ /^\t\t\t<key>(.*)<\/key><(date|integer|string)>(.*)<\/.*>$/ key = $1.downcase.split.join("_").intern track[key] = entities.decode($3.to_s) next elsif line =~ /^\t\t<\/dict>$/ then @tracks.push(track.dup) track.clear next elsif in_tracks && line =~ /^\t<\/dict>$/ in_tracks = false next else next end end end end |