Class: Phonology::SoundSequence

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

Overview

A collection of sounds

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#orthographyObject



36
37
38
# File 'lib/phonology/sound_sequence.rb', line 36

def orthography
  compact.map(&:orthography).join
end

#sonorityObject



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

#symbolsObject 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_aObject



12
13
14
# File 'lib/phonology/sound_sequence.rb', line 12

def to_a
  @sounds
end