Skip to content

Instantly share code, notes, and snippets.

@codabrink
Created October 24, 2011 16:55
Show Gist options
  • Save codabrink/1309503 to your computer and use it in GitHub Desktop.
Save codabrink/1309503 to your computer and use it in GitHub Desktop.
NMLParse.rb
require "rexml/document"
require "NMLParse/song"
class NMLParse
attr_accessor :songs
def initialize
@songs = []
end
def self.read(path)
nml = self.new
file = File.new(path)
doc = REXML::Document.new file
doc.elemens.each("entry") { |entry|
next if !entry.attributes["title"] && !entry.attributes["artist"] #skips blank lines
nml.add_song do |song|
song.title = entry.attributes["title"]
song.artist = entry.attributes["artist"]
end
}
nml
end
def add_song(&block)
new_song = NMLParse::Song.new
yield(new_song)
@songs << new_song
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment