Class: HeadMusic::Content::Syllable
- Inherits:
-
Object
- Object
- HeadMusic::Content::Syllable
- Defined in:
- lib/head_music/content/syllable.rb
Overview
A sung syllable attached to a Placement for one verse. Only the minimal
linguistic fact is stored: the text, its verse number, and whether the word
continues onto the next sung note (hyphen_after). The MusicXML syllabic
value (single/begin/middle/end) is derived from these at render time rather
than stored, and melisma is represented by the absence of a syllable on the
following placements, so nothing here encodes it.
Instance Attribute Summary collapse
-
#hyphen_after ⇒ Object
readonly
Returns the value of attribute hyphen_after.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#verse ⇒ Object
readonly
Returns the value of attribute verse.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
-
#hyphen_after? ⇒ Boolean
-
#initialize(text, verse: 1, hyphen_after: false) ⇒ Syllable
constructor
A new instance of Syllable.
-
#to_h ⇒ Object
Constructor Details
#initialize(text, verse: 1, hyphen_after: false) ⇒ Syllable
Returns a new instance of Syllable.
13 14 15 16 17 18 |
# File 'lib/head_music/content/syllable.rb', line 13 def initialize(text, verse: 1, hyphen_after: false) @text = text.to_s @verse = Integer(verse) @hyphen_after = !!hyphen_after freeze end |
Instance Attribute Details
#hyphen_after ⇒ Object (readonly)
Returns the value of attribute hyphen_after.
11 12 13 |
# File 'lib/head_music/content/syllable.rb', line 11 def hyphen_after @hyphen_after end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/head_music/content/syllable.rb', line 11 def text @text end |
#verse ⇒ Object (readonly)
Returns the value of attribute verse.
11 12 13 |
# File 'lib/head_music/content/syllable.rb', line 11 def verse @verse end |
Class Method Details
.from_h(hash) ⇒ Object
31 32 33 |
# File 'lib/head_music/content/syllable.rb', line 31 def self.from_h(hash) new(hash["text"], verse: hash.fetch("verse", 1), hyphen_after: hash.fetch("hyphen_after", false)) end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 |
# File 'lib/head_music/content/syllable.rb', line 35 def ==(other) other.is_a?(self.class) && to_h == other.to_h end |
#hyphen_after? ⇒ Boolean
20 21 22 |
# File 'lib/head_music/content/syllable.rb', line 20 def hyphen_after? hyphen_after end |
#to_h ⇒ Object
24 25 26 27 28 29 |
# File 'lib/head_music/content/syllable.rb', line 24 def to_h hash = {"text" => text} hash["verse"] = verse unless verse == 1 hash["hyphen_after"] = true if hyphen_after hash end |