Class: Phonology::RulesDSL
- Inherits:
-
Object
- Object
- Phonology::RulesDSL
show all
- Defined in:
- lib/phonology/rule.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(array) ⇒ RulesDSL
Returns a new instance of RulesDSL.
7
8
9
|
# File 'lib/phonology/rule.rb', line 7
def initialize(array)
@array = array
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
11
12
13
|
# File 'lib/phonology/rule.rb', line 11
def method_missing(sym, *args, &block)
curr_sound.__send__(sym, *args, &block)
end
|
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
5
6
7
|
# File 'lib/phonology/rule.rb', line 5
def array
@array
end
|
Instance Method Details
#apply(&block) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/phonology/rule.rb', line 15
def apply(&block)
array.each_index.map do |index|
@index = index
instance_eval(&block)
get_result
end
end
|
#curr_sound ⇒ Object
35
36
37
|
# File 'lib/phonology/rule.rb', line 35
def curr_sound
array[@index]
end
|
#delete(*args) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/phonology/rule.rb', line 23
def delete(*args)
if !args.empty?
curr_sound.delete(*args)
else
array[@index] = nil
end
end
|
#devoice ⇒ Object
51
52
53
|
# File 'lib/phonology/rule.rb', line 51
def devoice
curr_sound >> :voiced
end
|
#final? ⇒ Boolean
79
80
81
|
# File 'lib/phonology/rule.rb', line 79
def final?
@index == @max
end
|
#follows(*features) ⇒ Object
61
62
63
64
65
|
# File 'lib/phonology/rule.rb', line 61
def follows(*features)
return false if initial?
features.flatten.each {|f| return false unless prev_sound.send(:"#{f}?")}
true
end
|
#initial? ⇒ Boolean
75
76
77
|
# File 'lib/phonology/rule.rb', line 75
def initial?
@index == 0
end
|
#insert(*args) ⇒ Object
31
32
33
|
# File 'lib/phonology/rule.rb', line 31
def insert(*args)
@result = [curr_sound, Sound.new(*args)]
end
|
#next_sound(offset = 1) ⇒ Object
39
40
41
|
# File 'lib/phonology/rule.rb', line 39
def next_sound(offset = 1)
!final? && array[@index + offset]
end
|
#precedes(*features) ⇒ Object
55
56
57
58
59
|
# File 'lib/phonology/rule.rb', line 55
def precedes(*features)
return false if !next_sound
features.flatten.each {|f| return false unless next_sound.send(:"#{f}?")}
true
end
|
#prev_sound(offset = 1) ⇒ Object
43
44
45
|
# File 'lib/phonology/rule.rb', line 43
def prev_sound(offset = 1)
!initial? && array[@index - offset]
end
|
#syllable_final? ⇒ Boolean
71
72
73
|
# File 'lib/phonology/rule.rb', line 71
def syllable_final?
syllable.coda.last == curr_sound
end
|
#syllable_initial? ⇒ Boolean
67
68
69
|
# File 'lib/phonology/rule.rb', line 67
def syllable_initial?
syllable.onset.first == curr_sound
end
|
#voice ⇒ Object
47
48
49
|
# File 'lib/phonology/rule.rb', line 47
def voice
curr_sound << :voiced
end
|