Class: Clef::Notation::Lyric

Inherits:
Object
  • Object
show all
Defined in:
lib/clef/notation/lyric.rb

Constant Summary collapse

HYPHEN =
"--"
EXTENDER =
"_"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(voice_id, text) ⇒ Lyric

Returns a new instance of Lyric.

Parameters:

  • voice_id (Symbol)
  • text (String)

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
# File 'lib/clef/notation/lyric.rb', line 13

def initialize(voice_id, text)
  raise ArgumentError, "text must be String" unless text.is_a?(String)

  @voice_id = voice_id
  @text = text
  @syllables = parse_syllables(text)
end

Instance Attribute Details

#syllablesObject (readonly)

Returns the value of attribute syllables.



9
10
11
# File 'lib/clef/notation/lyric.rb', line 9

def syllables
  @syllables
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/clef/notation/lyric.rb', line 9

def text
  @text
end

#voice_idObject (readonly)

Returns the value of attribute voice_id.



9
10
11
# File 'lib/clef/notation/lyric.rb', line 9

def voice_id
  @voice_id
end

Class Method Details

.extender?(syllable) ⇒ Boolean

Parameters:

  • syllable (String)

Returns:

  • (Boolean)


40
41
42
# File 'lib/clef/notation/lyric.rb', line 40

def self.extender?(syllable)
  syllable == EXTENDER
end

.hyphen?(syllable) ⇒ Boolean

Parameters:

  • syllable (String)

Returns:

  • (Boolean)


34
35
36
# File 'lib/clef/notation/lyric.rb', line 34

def self.hyphen?(syllable)
  syllable == HYPHEN
end

.note_syllable?(syllable) ⇒ Boolean

Parameters:

  • syllable (String)

Returns:

  • (Boolean)


28
29
30
# File 'lib/clef/notation/lyric.rb', line 28

def self.note_syllable?(syllable)
  syllable != HYPHEN
end

Instance Method Details

#note_slot_countInteger

Returns:

  • (Integer)


22
23
24
# File 'lib/clef/notation/lyric.rb', line 22

def note_slot_count
  syllables.count { |syllable| self.class.note_syllable?(syllable) }
end