Class: Phonology::Syllable Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/phonology/syllable.rb

Overview

This class is abstract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sound = nil) ⇒ Syllable

Returns a new instance of Syllable.



7
8
9
10
11
12
# File 'lib/phonology/syllable.rb', line 7

def initialize(sound = nil)
  @onset = ::Phonology::SoundSequence.new
  @nucleus = ::Phonology::SoundSequence.new
  @coda = ::Phonology::SoundSequence.new
  add sound if sound
end

Instance Attribute Details

#codaObject

Returns the value of attribute coda.



5
6
7
# File 'lib/phonology/syllable.rb', line 5

def coda
  @coda
end

#nucleusObject

Returns the value of attribute nucleus.



5
6
7
# File 'lib/phonology/syllable.rb', line 5

def nucleus
  @nucleus
end

#onsetObject

Returns the value of attribute onset.



5
6
7
# File 'lib/phonology/syllable.rb', line 5

def onset
  @onset
end

#stressObject

Returns the value of attribute stress.



5
6
7
# File 'lib/phonology/syllable.rb', line 5

def stress
  @stress
end

Instance Method Details

#<<(sound) ⇒ Object Also known as: add



46
47
48
49
50
51
52
53
54
55
# File 'lib/phonology/syllable.rb', line 46

def <<(sound)
  if onset_wants?(sound)
    @onset << sound
  elsif nucleus_wants?(sound)
    @nucleus << sound
  else
    @coda << sound
  end
  sound.syllable = self
end

#coda_wants?(sound) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/phonology/syllable.rb', line 42

def coda_wants?(sound)
  raise NotImplementedError
end

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/phonology/syllable.rb', line 58

def empty?
  onset.empty? && nucleus.empty? && coda.empty?
end

#nucleus_wants?(sound) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/phonology/syllable.rb', line 38

def nucleus_wants?(sound)
  raise NotImplementedError
end

#onset_wants?(sound) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/phonology/syllable.rb', line 34

def onset_wants?(sound)
  raise NotImplementedError
end

#rimeObject



22
23
24
# File 'lib/phonology/syllable.rb', line 22

def rime
  [nucleus, coda]
end

#to_aObject



14
15
16
# File 'lib/phonology/syllable.rb', line 14

def to_a
  [onset.to_a, rime.map(&:to_a)].flatten
end

#to_s(show_stress = true) ⇒ Object



26
27
28
# File 'lib/phonology/syllable.rb', line 26

def to_s(show_stress = true)
  (show_stress && stress ? IPA.primary_stress : "") + to_a.map(&:symbol).join
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/phonology/syllable.rb', line 18

def valid?
  !nucleus.empty?
end

#wants?(sound) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/phonology/syllable.rb', line 30

def wants?(sound)
  onset_wants?(sound) or nucleus_wants?(sound) or coda_wants?(sound)
end