Class: HeadMusic::Bar

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/content/bar.rb

Overview

Representation of a bar in a composition Encapsulates meter and key signature changes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(composition, key_signature: nil, meter: nil) ⇒ Bar

Returns a new instance of Bar.



9
10
11
12
13
# File 'lib/head_music/content/bar.rb', line 9

def initialize(composition, key_signature: nil, meter: nil)
  @composition = composition
  @key_signature = HeadMusic::KeySignature.get(key_signature) if key_signature
  @meter = HeadMusic::Meter.get(meter) if meter
end

Instance Attribute Details

#compositionObject (readonly)

Returns the value of attribute composition.



6
7
8
# File 'lib/head_music/content/bar.rb', line 6

def composition
  @composition
end

#key_signatureObject

Returns the value of attribute key_signature.



7
8
9
# File 'lib/head_music/content/bar.rb', line 7

def key_signature
  @key_signature
end

#meterObject

Returns the value of attribute meter.



7
8
9
# File 'lib/head_music/content/bar.rb', line 7

def meter
  @meter
end

Instance Method Details

#to_sObject



15
16
17
# File 'lib/head_music/content/bar.rb', line 15

def to_s
  ["Bar", key_signature, meter].compact.join(" ")
end