Module: MusicalScore::IO

Defined in:
lib/musical_score/io/exporter.rb,
lib/musical_score/io/importer.rb

Class Method Summary collapse

Class Method Details

.export_xml(path, score) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/musical_score/io/exporter.rb', line 6

def export_xml(path, score)
    formatter = REXML::Formatters::Pretty.new(4)
    formatter.compact = true
    File.open(path, 'w') do |file|
        formatter.write(score.export_xml, file)
    end
end

.import(file) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/musical_score/io/importer.rb', line 6

def import(file)
    extname = File.extname(file)
    case extname
    when ".xml"
        return import_xml_via_hash(file)
    else
        raise MusicalScore::InvalidFileType
    end
end

.import_xml(file_path) ⇒ Object



15
16
17
18
19
# File 'lib/musical_score/io/importer.rb', line 15

def import_xml(file_path)
    doc = REXML::Document.new(File.new(file_path))
    score = MusicalScore::Score::Score.create_by_xml(doc, file_path)
    return score
end

.import_xml_via_hash(file_path) ⇒ Object



21
22
23
24
25
# File 'lib/musical_score/io/importer.rb', line 21

def import_xml_via_hash(file_path)
    doc = XmlSimple.xml_in(open(file_path))
    score = MusicalScore::Score::Score.create_by_hash(doc, file_path)
    return score
end