Class: HeadMusic::Content::Syllable

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_afterObject (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

#textObject (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/head_music/content/syllable.rb', line 11

def text
  @text
end

#verseObject (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/head_music/content/syllable.rb', line 20

def hyphen_after?
  hyphen_after
end

#to_hObject



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