require 'playlist' class Radiodan class MPD module PlaylistParser def self.parse(attributes={}, tracks=[]) options = parse_attributes(attributes) options[:tracks] = parse_tracks(tracks) Playlist.new(options) end private def self.parse_attributes(attributes) options = {} options[:state] = attributes['state'].to_sym options[:mode] = parse_mode(attributes) options[:repeat] = attributes['repeat'] == '1' options[:position] = attributes['song'].to_i options[:seek] = attributes['elapsed'].to_f options[:volume] = attributes['volume'].to_i options end def self.parse_tracks(tracks) p tracks.first.inspect tracks.collect{ |t| Track.new(t) } end def self.parse_mode(attributes) attributes['random'] == '1' ? :random : :sequential end end end end