Class: Phonology::SoundSequence
- Inherits:
-
Object
- Object
- Phonology::SoundSequence
- Defined in:
- lib/phonology/sound_sequence.rb
Overview
A collection of sounds
Instance Attribute Summary collapse
-
#sounds ⇒ Object
readonly
Returns the value of attribute sounds.
Instance Method Summary collapse
-
#apply_rule(rule) ⇒ Object
Apply rule and get a new instance of SoundSequence.
-
#apply_rule!(rule) ⇒ Object
Apply rule in place.
-
#initialize(arg = nil) ⇒ SoundSequence
constructor
A new instance of SoundSequence.
- #method_missing(sym, *args, &block) ⇒ Object
- #orthography ⇒ Object
- #sonority ⇒ Object
- #syllables(syllabifier) ⇒ Object
- #symbols ⇒ Object (also: #ipa, #to_s, #to_str)
- #to_a ⇒ Object
Constructor Details
#initialize(arg = nil) ⇒ SoundSequence
Returns a new instance of SoundSequence.
16 17 18 19 20 21 22 23 |
# File 'lib/phonology/sound_sequence.rb', line 16 def initialize(arg = nil) # String of ipa symbols if arg.kind_of? String @sounds = arg.split('').map {|letter| Sound.new(letter)} else @sounds = [arg].flatten.compact end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
8 9 10 |
# File 'lib/phonology/sound_sequence.rb', line 8 def method_missing(sym, *args, &block) @sounds.__send__(sym, *args, &block) end |
Instance Attribute Details
#sounds ⇒ Object (readonly)
Returns the value of attribute sounds.
6 7 8 |
# File 'lib/phonology/sound_sequence.rb', line 6 def sounds @sounds end |
Instance Method Details
#apply_rule(rule) ⇒ Object
Apply rule and get a new instance of SoundSequence.
41 42 43 |
# File 'lib/phonology/sound_sequence.rb', line 41 def apply_rule(rule) self.class.new rule.apply(@sounds) end |
#apply_rule!(rule) ⇒ Object
Apply rule in place.
46 47 48 49 |
# File 'lib/phonology/sound_sequence.rb', line 46 def apply_rule!(rule) @sounds = rule.apply(@sounds) self end |
#orthography ⇒ Object
36 37 38 |
# File 'lib/phonology/sound_sequence.rb', line 36 def orthography compact.map(&:orthography).join end |
#sonority ⇒ Object
51 52 53 |
# File 'lib/phonology/sound_sequence.rb', line 51 def sonority @sounds.empty? ? nil : @sounds.last.sonority end |
#syllables(syllabifier) ⇒ Object
25 26 27 |
# File 'lib/phonology/sound_sequence.rb', line 25 def syllables(syllabifier) @syllables ||= syllabifier.syllabify(self) end |
#symbols ⇒ Object Also known as: ipa, to_s, to_str
29 30 31 |
# File 'lib/phonology/sound_sequence.rb', line 29 def symbols compact.map(&:symbol).join end |
#to_a ⇒ Object
12 13 14 |
# File 'lib/phonology/sound_sequence.rb', line 12 def to_a @sounds end |