Module: Phonology::OrthographyTranslatorDSL

Included in:
OrthographyTranslator
Defined in:
lib/phonology/orthography.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



7
8
9
# File 'lib/phonology/orthography.rb', line 7

def method_missing(sym, *args, &block)
  last_sound.__send__(sym, *args, &block)
end

Instance Attribute Details

#anticipationObject

Returns the value of attribute anticipation.



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

def anticipation
  @anticipation
end

#last_soundObject

Returns the value of attribute last_sound.



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

def last_sound
  @last_sound
end

Instance Method Details

#anticipate(&block) ⇒ Object



16
17
18
19
# File 'lib/phonology/orthography.rb', line 16

def anticipate(&block)
  @anticipation = block
  nil
end

#between(before, after) ⇒ Object



48
49
50
# File 'lib/phonology/orthography.rb', line 48

def between(before, after)
  follows(*before) && precedes(*after)
end

#context(before, after) ⇒ Object



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

def context(before, after)
  string.downcase[offset - before.length, before.length] == before &&
  string.downcase[offset + 1, after.length] == after
end

#curr_charObject



21
22
23
# File 'lib/phonology/orthography.rb', line 21

def curr_char
  array[@index]
end

#final?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/phonology/orthography.rb', line 56

def final?
  !next_char
end

#follows(*chars) ⇒ Object



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

def follows(*chars)
  chars.flatten.each {|c| return true if c == prev_char}
  false
end

#get(*features) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/phonology/orthography.rb', line 60

def get(*features)
  if features.first.kind_of?(Array)
    get_affricate(*features)
  else
    match = sounds.with_all(*features)
    return nil if match.sets.empty? || match.sets.length > 1
    @last_sound = Sound.new *match.sets.keys.first.to_a
  end
  @last_sound.orthography = curr_char
  do_anticipation
end

#initial?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/phonology/orthography.rb', line 52

def initial?
  @index == 0
end

#next_char(offset = 1) ⇒ Object



25
26
27
# File 'lib/phonology/orthography.rb', line 25

def next_char(offset = 1)
  array[@index + offset]
end

#offsetObject



44
45
46
# File 'lib/phonology/orthography.rb', line 44

def offset
  @index
end

#precedes(*chars) ⇒ Object



38
39
40
41
42
# File 'lib/phonology/orthography.rb', line 38

def precedes(*chars)
  return false if !next_char
  chars.flatten.each {|c| return true if c == next_char}
  false
end

#prev_char(offset = 1) ⇒ Object



29
30
31
# File 'lib/phonology/orthography.rb', line 29

def prev_char(offset = 1)
  array[@index - offset] unless @index == 0
end