Class: ITunes::XMLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes/xml_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ XMLParser



14
15
16
17
# File 'lib/itunes/xml_parser.rb', line 14

def initialize(params = {})
  @file_name = params[:file]
  parse if @file_name
end

Instance Attribute Details

#parsedObject (readonly)

self.parse



12
13
14
# File 'lib/itunes/xml_parser.rb', line 12

def parsed
  @parsed
end

Class Method Details

.parse(xml, params = {}) ⇒ Object



8
9
10
# File 'lib/itunes/xml_parser.rb', line 8

def self.parse(xml, params = {})
  new(params.merge(:file => xml))
end

Instance Method Details

#add_path_to_track(id, track) ⇒ Object

process_tracks



45
46
47
# File 'lib/itunes/xml_parser.rb', line 45

def add_path_to_track(id, track)
  tracks[id]['Path'] = CGI.unescape(URI.parse(track['Location']).path)
end

#filesObject

tracks



27
28
29
30
31
32
33
34
35
# File 'lib/itunes/xml_parser.rb', line 27

def files
  @files ||= begin
    _files = [ ]
    tracks.each do |id, track|
      _files << track.merge(:path_on_file_system => CGI.unescape(URI(track['Location']).path))
    end
    _files
  end
end

#parse(params = {}) ⇒ Object

initialize



19
20
21
# File 'lib/itunes/xml_parser.rb', line 19

def parse(params = {})
  @parsed = Plist.parse_xml(@file_name)
end

#process_tracks(_tracks = @tracks) ⇒ Object

Performs additional processing to each tracks fields



39
40
41
42
43
# File 'lib/itunes/xml_parser.rb', line 39

def process_tracks(_tracks = @tracks)
  _tracks.dup.each do |id, track|
    add_path_to_track(id, track)
  end
end

#tracksObject

parse



23
24
25
# File 'lib/itunes/xml_parser.rb', line 23

def tracks
  @tracks ||= parsed['Tracks']
end