Class: Spanish::Syllable
- Inherits:
-
Object
- Object
- Spanish::Syllable
- Defined in:
- lib/spanish/syllable.rb
Defined Under Namespace
Classes: Syllables
Instance Attribute Summary collapse
-
#coda ⇒ Object
Returns the value of attribute coda.
-
#nucleus ⇒ Object
Returns the value of attribute nucleus.
-
#onset ⇒ Object
Returns the value of attribute onset.
-
#stress ⇒ Object
Returns the value of attribute stress.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(sound) ⇒ Object (also: #add)
- #coda_wants?(sound) ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(sound = nil) ⇒ Syllable
constructor
A new instance of Syllable.
- #nucleus_wants?(sound) ⇒ Boolean
- #onset_wants?(sound) ⇒ Boolean
- #rime ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #wants?(sound) ⇒ Boolean
Constructor Details
#initialize(sound = nil) ⇒ Syllable
Returns a new instance of Syllable.
8 9 10 11 12 13 |
# File 'lib/spanish/syllable.rb', line 8 def initialize(sound = nil) @onset = [] @nucleus = [] @coda = [] add sound if sound end |
Instance Attribute Details
#coda ⇒ Object
Returns the value of attribute coda.
6 7 8 |
# File 'lib/spanish/syllable.rb', line 6 def coda @coda end |
#nucleus ⇒ Object
Returns the value of attribute nucleus.
6 7 8 |
# File 'lib/spanish/syllable.rb', line 6 def nucleus @nucleus end |
#onset ⇒ Object
Returns the value of attribute onset.
6 7 8 |
# File 'lib/spanish/syllable.rb', line 6 def onset @onset end |
#stress ⇒ Object
Returns the value of attribute stress.
6 7 8 |
# File 'lib/spanish/syllable.rb', line 6 def stress @stress end |
Class Method Details
.apply_stress(syllables) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/spanish/syllable.rb', line 83 def self.apply_stress(syllables) if syllables.detect {|s| s.stress} elsif syllables.length == 1 syllables[0].stress = true else last = syllables.last.to_a penult = syllables[-2].to_a if last.last.vocalic? or last.last.nasal? or (last.last.alveolar? && last.last.fricative?) syllables[-2].stress = true else syllables.last.stress = true end end syllables end |
.syllabify(arg) ⇒ Object
99 100 101 102 |
# File 'lib/spanish/syllable.rb', line 99 def self.syllabify(arg) arg = arg.kind_of?(String) ? Spanish.get_sounds(arg) : arg apply_stress(Syllables.new(arg).entries) end |
Instance Method Details
#<<(sound) ⇒ Object Also known as: add
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/spanish/syllable.rb', line 67 def <<(sound) @stress = true if sound.hints.include?(:primary_stress) if onset_wants?(sound) @onset << sound elsif nucleus_wants?(sound) @nucleus << sound else @coda << sound end end |
#coda_wants?(sound) ⇒ Boolean
58 59 60 61 62 63 64 65 |
# File 'lib/spanish/syllable.rb', line 58 def coda_wants?(sound) if nucleus.empty? false else # Codas don't want a rising dipthong but will accept one at the end of words. sound.consonantal? && !(sound.approximant? && sound.palatal?) end end |
#empty? ⇒ Boolean
79 80 81 |
# File 'lib/spanish/syllable.rb', line 79 def empty? onset.empty? && nucleus.empty? && coda.empty? end |
#nucleus_wants?(sound) ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/spanish/syllable.rb', line 46 def nucleus_wants?(sound) if !coda.empty? || nucleus.length == 2 || !sound.vocalic? false elsif nucleus.empty? true elsif nucleus.last != sound !nucleus.last.hints.include?(:primary_stress) && !sound.hints.include?(:syllable_boundary) && (nucleus.last.close? || !nucleus.last.close? && sound.close?) end end |
#onset_wants?(sound) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'lib/spanish/syllable.rb', line 36 def onset_wants?(sound) if !nucleus.empty? || sound.vocalic? false elsif onset.empty? sound.consonantal? else sound.liquid? || sound.approximant? end end |
#rime ⇒ Object
23 24 25 |
# File 'lib/spanish/syllable.rb', line 23 def rime [nucleus, coda] end |
#to_a ⇒ Object
15 16 17 |
# File 'lib/spanish/syllable.rb', line 15 def to_a [onset, rime].flatten end |
#to_s ⇒ Object
27 28 29 30 |
# File 'lib/spanish/syllable.rb', line 27 def to_s string = to_a.map(&:symbol).join (stress ? "\u02c8" : "") + string end |
#valid? ⇒ Boolean
19 20 21 |
# File 'lib/spanish/syllable.rb', line 19 def valid? !nucleus.empty? end |
#wants?(sound) ⇒ Boolean
32 33 34 |
# File 'lib/spanish/syllable.rb', line 32 def wants?(sound) onset_wants?(sound) or nucleus_wants?(sound) or coda_wants?(sound) end |