Class: HeadMusic::Notation::StaffPosition
- Inherits:
-
Object
- Object
- HeadMusic::Notation::StaffPosition
- Defined in:
- lib/head_music/notation/staff_position.rb
Constant Summary collapse
- NAMES =
{ -2 => ["ledger line below staff"], -1 => ["space below staff"], 0 => ["bottom line", "line 1"], 1 => ["bottom space", "space 1"], 2 => ["line 2"], 3 => ["space 2"], 4 => ["middle line", "line 3"], 5 => ["space 3"], 6 => ["line 4"], 7 => ["space 4"], 8 => ["top line", "line 5"], 9 => ["space above staff"], 10 => ["ledger line above staff"] }.freeze
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Integer, even = line, odd = space; bottom line = 0.
Class Method Summary collapse
-
.name_to_index(name) ⇒ Object
Accepts a name (string or symbol) and returns the corresponding StaffPosition index (integer), or nil if not found.
Instance Method Summary collapse
-
#initialize(index) ⇒ StaffPosition
constructor
A new instance of StaffPosition.
-
#line? ⇒ Boolean
-
#line_number ⇒ Object
-
#space? ⇒ Boolean
-
#space_number ⇒ Object
-
#to_s ⇒ Object
Constructor Details
#initialize(index) ⇒ StaffPosition
Returns a new instance of StaffPosition.
35 36 37 |
# File 'lib/head_music/notation/staff_position.rb', line 35 def initialize(index) @index = index end |
Instance Attribute Details
#index ⇒ Object (readonly)
Integer, even = line, odd = space; bottom line = 0
5 6 7 |
# File 'lib/head_music/notation/staff_position.rb', line 5 def index @index end |
Class Method Details
.name_to_index(name) ⇒ Object
Accepts a name (string or symbol) and returns the corresponding StaffPosition index (integer), or nil if not found
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/head_music/notation/staff_position.rb', line 24 def self.name_to_index(name) NAMES.each do |index, names| if names.map { |n| HeadMusic::Utilities::Case.to_snake_case(n) }.include?(HeadMusic::Utilities::Case.to_snake_case(name)) return index end end nil end |
Instance Method Details
#line? ⇒ Boolean
39 40 41 |
# File 'lib/head_music/notation/staff_position.rb', line 39 def line? index.even? end |
#line_number ⇒ Object
47 48 49 50 |
# File 'lib/head_music/notation/staff_position.rb', line 47 def line_number return nil unless line? (index / 2) + 1 end |
#space? ⇒ Boolean
43 44 45 |
# File 'lib/head_music/notation/staff_position.rb', line 43 def space? index.odd? end |
#space_number ⇒ Object
52 53 54 55 |
# File 'lib/head_music/notation/staff_position.rb', line 52 def space_number return nil unless space? ((index - 1) / 2) + 1 end |