Class: Clef::Core::StaffGroup
- Inherits:
-
Object
- Object
- Clef::Core::StaffGroup
- Defined in:
- lib/clef/core/staff_group.rb
Constant Summary collapse
- BRACKETS =
%i[bracket brace none].freeze
Instance Attribute Summary collapse
-
#bracket_type ⇒ Object
readonly
Returns the value of attribute bracket_type.
Instance Method Summary collapse
- #add_staff(staff) ⇒ StaffGroup
-
#initialize(staves = [], bracket_type: :none) ⇒ StaffGroup
constructor
A new instance of StaffGroup.
- #staves ⇒ Array<Staff>
Constructor Details
#initialize(staves = [], bracket_type: :none) ⇒ StaffGroup
Returns a new instance of StaffGroup.
12 13 14 15 16 17 18 |
# File 'lib/clef/core/staff_group.rb', line 12 def initialize(staves = [], bracket_type: :none) raise ArgumentError, "unsupported bracket type" unless BRACKETS.include?(bracket_type) @staves = [] @bracket_type = bracket_type staves.each { |staff| add_staff(staff) } end |
Instance Attribute Details
#bracket_type ⇒ Object (readonly)
Returns the value of attribute bracket_type.
8 9 10 |
# File 'lib/clef/core/staff_group.rb', line 8 def bracket_type @bracket_type end |
Instance Method Details
#add_staff(staff) ⇒ StaffGroup
22 23 24 25 26 27 28 |
# File 'lib/clef/core/staff_group.rb', line 22 def add_staff(staff) raise ArgumentError, "staff must be a Clef::Core::Staff" unless staff.is_a?(Staff) raise ArgumentError, "duplicate staff id: #{staff.id}" if @staves.any? { |item| item.id == staff.id } @staves << staff self end |
#staves ⇒ Array<Staff>
31 32 33 |
# File 'lib/clef/core/staff_group.rb', line 31 def staves @staves.dup.freeze end |