Class: Musa::MusicXML::Builder::Internal::Time

Inherits:
Object
  • Object
show all
Includes:
Helper::ToXML
Defined in:
lib/musa-dsl/musicxml/builder/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::ToXML

#to_xml

Constructor Details

#initialize(number = nil, senza_misura: nil, beats: nil, beat_type: nil) ⇒ Time

Returns a new instance of Time.



44
45
46
47
48
49
50
51
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 44

def initialize(number = nil, senza_misura: nil, beats: nil, beat_type: nil)
  @number = number

  @senza_misura = senza_misura unless beats && beat_type
  @beats = []

  add_beats beats: beats, beat_type: beat_type if beats && beat_type
end

Instance Attribute Details

#beatsObject (readonly)

Returns the value of attribute beats.



55
56
57
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 55

def beats
  @beats
end

#numberObject (readonly)

Returns the value of attribute number.



53
54
55
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 53

def number
  @number
end

#senza_misuraObject

Returns the value of attribute senza_misura.



54
55
56
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 54

def senza_misura
  @senza_misura
end

Instance Method Details

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



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 61

def _to_xml(io, indent:, tabs:)
  io.puts "#{tabs}<time#{" number=\"#{@number.to_i}\"" if @number}>"

  io.puts "#{tabs}\t<senza-misura>#{@senza_misura}</senza-misura>" if @senza_misura
  @beats.each do |beats|
    io.puts "#{tabs}\t<beats>#{beats[:beats].to_i}</beats>"
    io.puts "#{tabs}\t<beat-type>#{beats[:beat_type].to_i}</beat-type>"
  end

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

#add_beats(beats:, beat_type:) ⇒ Object



57
58
59
# File 'lib/musa-dsl/musicxml/builder/attributes.rb', line 57

def add_beats(beats:, beat_type:)
  @beats << { beats: beats, beat_type: beat_type }
end