Class: Clef::Core::Staff
- Inherits:
-
Object
- Object
- Clef::Core::Staff
- Includes:
- Metadata
- Defined in:
- lib/clef/core/staff.rb
Instance Attribute Summary collapse
-
#clef ⇒ Object
readonly
Returns the value of attribute clef.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key_signature ⇒ Object
Returns the value of attribute key_signature.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#time_signature ⇒ Object
Returns the value of attribute time_signature.
Instance Method Summary collapse
- #add_measure(measure) ⇒ Staff
-
#initialize(id, name: nil, clef: Clef.new(:treble)) ⇒ Staff
constructor
A new instance of Staff.
- #measures ⇒ Array<Measure>
Methods included from Metadata
#metadata, #metadata=, #set_metadata, #update_metadata
Constructor Details
#initialize(id, name: nil, clef: Clef.new(:treble)) ⇒ Staff
Returns a new instance of Staff.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/clef/core/staff.rb', line 14 def initialize(id, name: nil, clef: Clef.new(:treble)) raise ArgumentError, "id must be provided" if id.nil? raise ArgumentError, "clef must be a Clef::Core::Clef" unless clef.is_a?(Clef) @id = id @name = name || id.to_s @clef = clef @measures = [] @metadata = {} end |
Instance Attribute Details
#clef ⇒ Object (readonly)
Returns the value of attribute clef.
8 9 10 |
# File 'lib/clef/core/staff.rb', line 8 def clef @clef end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/clef/core/staff.rb', line 8 def id @id end |
#key_signature ⇒ Object
Returns the value of attribute key_signature.
9 10 11 |
# File 'lib/clef/core/staff.rb', line 9 def key_signature @key_signature end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/clef/core/staff.rb', line 8 def name @name end |
#time_signature ⇒ Object
Returns the value of attribute time_signature.
9 10 11 |
# File 'lib/clef/core/staff.rb', line 9 def time_signature @time_signature end |
Instance Method Details
#add_measure(measure) ⇒ Staff
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/clef/core/staff.rb', line 27 def add_measure(measure) raise ArgumentError, "measure must be a Clef::Core::Measure" unless measure.is_a?(Measure) raise ArgumentError, "duplicate measure number: #{measure.number}" if @measures.any? { |item| item.number == measure.number } if @measures.any? && measure.number < @measures.last.number raise ArgumentError, "measure numbers must be added in ascending order" end @measures << measure self end |
#measures ⇒ Array<Measure>
39 40 41 |
# File 'lib/clef/core/staff.rb', line 39 def measures @measures.dup.freeze end |