Class: Musa::MusicXML::Builder::Internal::Part

Inherits:
Object
  • Object
show all
Extended by:
Extension::AttributeBuilder
Includes:
Extension::With, Helper::HeaderToXML, Helper::ToXML
Defined in:
lib/musa-dsl/musicxml/builder/part.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 Helper::ToXML

#to_xml

Methods included from Helper::HeaderToXML

#header_to_xml

Methods included from Extension::With

#with

Constructor Details

#initialize(id, name:, abbreviation: nil, **first_measure_attributes, &block) ⇒ Part

Returns a new instance of Part.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 18

def initialize(id, name:, abbreviation: nil, **first_measure_attributes, &block)
  @id = id
  @name = name
  @abbreviation = abbreviation

  @measures = []

  unless first_measure_attributes.empty?
    add_measure **first_measure_attributes
  end

  with &block if block_given?
end

Instance Method Details

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



49
50
51
52
53
54
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 49

def _header_to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<score-part id=\"#{@id}\">"
  io.puts "#{tabs}\t<part-name>#{@name}</part-name>"
  io.puts "#{tabs}\t<part-abbreviation>#{@abbreviation}</part-abbreviation>" if @abbreviation
  io.puts "#{tabs}</score-part>"
end

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



56
57
58
59
60
61
62
# File 'lib/musa-dsl/musicxml/builder/part.rb', line 56

def _to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<part id=\"#{@id}\">"
  @measures.each do |measure|
    measure.to_xml(io, indent: indent + 1)
  end
  io.puts "#{tabs}</part>"
end