Class: Migemo

Inherits:
Object
  • Object
show all
Defined in:
lib/migemo.rb,
lib/migemo/version.rb

Defined Under Namespace

Modules: VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, dict = nil) ⇒ Migemo

Returns a new instance of Migemo.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/migemo.rb', line 22

def initialize (pattern, dict=nil)
  @static_dict = if dict.nil?
                   MigemoStaticDict.new(File.dirname(File.expand_path(__FILE__)) + '/../data/migemo-dict')
                 elsif dict.is_a?(String)
                   MigemoStaticDict.new(dict)
                 else
                   dict
                 end
  @type = "ruby"
  @pattern = pattern
  @insertion = ""
  @optimization = 3

  @dict_cache = nil
  @user_dict = nil
  @regex_dict = nil
  @with_paren = false
end

Instance Attribute Details

#dict_cacheObject

Returns the value of attribute dict_cache.



43
44
45
# File 'lib/migemo.rb', line 43

def dict_cache
  @dict_cache
end

#insertionObject

Returns the value of attribute insertion.



42
43
44
# File 'lib/migemo.rb', line 42

def insertion
  @insertion
end

#optimizationObject

Returns the value of attribute optimization.



40
41
42
# File 'lib/migemo.rb', line 40

def optimization
  @optimization
end

#regex_dictObject

Returns the value of attribute regex_dict.



45
46
47
# File 'lib/migemo.rb', line 45

def regex_dict
  @regex_dict
end

#typeObject

Returns the value of attribute type.



41
42
43
# File 'lib/migemo.rb', line 41

def type
  @type
end

#user_dictObject

Returns the value of attribute user_dict.



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

def user_dict
  @user_dict
end

#with_parenObject

Returns the value of attribute with_paren.



46
47
48
# File 'lib/migemo.rb', line 46

def with_paren
  @with_paren
end

Instance Method Details

#lookupObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/migemo.rb', line 48

def lookup
  if @pattern == ""
    return RegexAlternation.new
  end
  result = if @dict_cache
             lookup_cache || lookup0
           else
             lookup0
           end
  if @user_dict
    lookup_user_dict.each{|x| result.push(x) }
  end
  result
end

#regexObject



67
68
69
70
71
72
73
74
# File 'lib/migemo.rb', line 67

def regex
  regex = lookup
  renderer = RegexRendererFactory.new(regex, @type, @insertion)
  renderer.with_paren = @with_paren
  string = renderer.render
  string = renderer.join_regexes(string, lookup_regex_dict) if @regex_dict
  string
end

#regex_treeObject



63
64
65
# File 'lib/migemo.rb', line 63

def regex_tree
  lookup
end