Class: Musa::MusicXML::Builder::Internal::Direction

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

#with

Constructor Details

#initialize(placement: nil, voice: nil, staff: nil, offset: nil, **directions, &block) ⇒ Direction

above / below



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/musa-dsl/musicxml/builder/direction.rb', line 17

def initialize(placement: nil, # above / below
               voice: nil, # number
               staff: nil,  # number
               offset: nil, # number
               **directions,
               &block)

  @placement = placement

  @types = []
  @voice = voice
  @staff = staff
  @offset = offset

  directions.each_pair do |direction, value|
    send direction, value
  end

  with &block if block_given?
end

Instance Method Details

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



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/musa-dsl/musicxml/builder/direction.rb', line 52

def _to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<direction#{ decode_bool_or_string_attribute(@placement, 'placement') }>"

  @types.each do |type|
    type.to_xml(io, indent: indent + 1)
  end

  io.puts "#{tabs}\t<offset sound=\"no\">#{@offset.to_f.round(2)}</offset>" if @offset
  io.puts "#{tabs}\t<voice>#{@voice.to_i}</voice>" if @voice
  io.puts "#{tabs}\t<staff>#{@staff.to_i}</staff>" if @staff

  io.puts "#{tabs}</direction>"
end