Class: Musa::MusicXML::Builder::ScorePartwise

Inherits:
Object
  • Object
show all
Extended by:
Extension::AttributeBuilder
Includes:
Extension::With, Internal::Helper::ToXML
Defined in:
lib/musa-dsl/musicxml/builder/score-partwise.rb

Instance Method Summary collapse

Methods included from Extension::AttributeBuilder

attr_complex_adder_to_array, attr_complex_adder_to_custom, attr_complex_builder, attr_simple_builder, attr_tuple_adder_to_array, attr_tuple_adder_to_hash, attr_tuple_builder

Methods included from Internal::Helper::ToXML

#to_xml

Methods included from Extension::With

#with

Constructor Details

#initialize(work_number: nil, work_title: nil, movement_number: nil, movement_title: nil, encoding_date: nil, creators: nil, rights: nil, &block) ⇒ ScorePartwise

Returns a new instance of ScorePartwise.



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/musa-dsl/musicxml/builder/score-partwise.rb', line 21

def initialize(work_number: nil, work_title: nil,
               movement_number: nil, movement_title: nil,
               encoding_date: nil,
               creators: nil,
               rights: nil,
               &block)

  @work_number = work_number
  @work_title = work_title
  @movement_number = movement_number
  @movement_title = movement_title

  @encoding_date = encoding_date || DateTime.now

  @creators = []
  @rights = []

  self.creators **creators if creators
  self.rights **rights if rights

  @groups_and_parts = []
  @parts = {}

  with &block if block_given?
end

Instance Method Details

#_to_xml(io, indent:, tabs:) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/musa-dsl/musicxml/builder/score-partwise.rb', line 71

def _to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
  io.puts "#{tabs}<!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 3.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\">"
  io.puts "#{tabs}<score-partwise version=\"3.0\">"

  if @work_number || @work_title
    io.puts"#{tabs}\t<work>"
    io.puts"#{tabs}\t\t<work-number>#{@work_number.to_i}</work-number>" if @work_number
    io.puts"#{tabs}\t\t<work-title>#{@work_title}</work-title>" if @work_title
    io.puts"#{tabs}\t</work>"
  end

  io.puts"#{tabs}\t<movement-number>#{@movement_number.to_i}</movement-number>" if @movement_number
  io.puts"#{tabs}\t<movement-title>#{@movement_title}</movement-title>" if @movement_title

  io.puts "#{tabs}\t<identification>"

  @creators.each do |creator|
    creator.to_xml(io, indent: indent + 2)
  end

  @rights.each do |rights|
    rights.to_xml(io, indent: indent + 2)
  end

  io.puts "#{tabs}\t\t<encoding>"
  io.puts"#{tabs}\t\t\t<encoding-date>#{@encoding_date.strftime("%Y-%m-%d")}</encoding-date>"
  io.puts"#{tabs}\t\t\t<software>MusaDSL: MusicXML output formatter</software>"
  io.puts "#{tabs}\t\t</encoding>"

  io.puts "#{tabs}\t</identification>"

  io.puts "#{tabs}\t<part-list>"
  @groups_and_parts.each do |group_or_part|
    group_or_part.header_to_xml(io, indent: indent + 2)
  end
  io.puts "#{tabs}\t</part-list>"

  @parts.each_value do |part|
    part.to_xml(io, indent: indent + 1)
  end

  io.puts "#{tabs}</score-partwise>"
end