Class: WordPart

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

Constant Summary collapse

DT_RULES =

arrays: [output, predecessor-rule, successor-rule]

DetranslitRules.rules
T_RULES =
TranslitRules.rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, prev, detranslit = true) ⇒ WordPart

Returns a new instance of WordPart.



16
17
18
19
20
# File 'lib/word_part.rb', line 16

def initialize input, prev, detranslit=true
  @input = input
  @prev = prev
  @is_detranslit = detranslit
end

Instance Attribute Details

#inputObject

may be more restricted than this



6
7
8
# File 'lib/word_part.rb', line 6

def input
  @input
end

#just_thruObject

may be more restricted than this



6
7
8
# File 'lib/word_part.rb', line 6

def just_thru
  @just_thru
end

#prevObject

may be more restricted than this



6
7
8
# File 'lib/word_part.rb', line 6

def prev
  @prev
end

#static_outputObject

may be more restricted than this



6
7
8
# File 'lib/word_part.rb', line 6

def static_output
  @static_output
end

#succObject

may be more restricted than this



6
7
8
# File 'lib/word_part.rb', line 6

def succ
  @succ
end

Class Method Details

.has_rules?(input, is_detranslit) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/word_part.rb', line 22

def self.has_rules? input, is_detranslit
  if is_detranslit
    DT_RULES.has_key? input
  else
    T_RULES.has_key? input
  end
end

Instance Method Details

#cyrillic_options(include_softeners) ⇒ Object

return array of (cyrillic) strings which can be empty (or nil instead?) –should we cache the result? i think it’s called no more than once.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/word_part.rb', line 31

def cyrillic_options(include_softeners)
  return [input] if just_thru #this can be set to accomodate for untranslatable characters.
  ret = []
  arr = @is_detranslit ? DT_RULES[input] : T_RULES[input]
  if arr #there are rules for this part, now see if any of them match
    arr.each do |rule|
      if match?(rule, include_softeners)
        ret << rule[0]
      end
    end
  end
  ret
end