Class: Migemo
- Inherits:
-
Object
- Object
- Migemo
- Defined in:
- lib/migemo.rb,
lib/migemo/version.rb
Defined Under Namespace
Modules: VERSION
Instance Attribute Summary collapse
-
#dict_cache ⇒ Object
Returns the value of attribute dict_cache.
-
#insertion ⇒ Object
Returns the value of attribute insertion.
-
#optimization ⇒ Object
Returns the value of attribute optimization.
-
#regex_dict ⇒ Object
Returns the value of attribute regex_dict.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user_dict ⇒ Object
Returns the value of attribute user_dict.
-
#with_paren ⇒ Object
Returns the value of attribute with_paren.
Instance Method Summary collapse
-
#initialize(pattern, dict = nil) ⇒ Migemo
constructor
A new instance of Migemo.
- #lookup ⇒ Object
- #regex ⇒ Object
- #regex_tree ⇒ Object
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.(__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_cache ⇒ Object
Returns the value of attribute dict_cache.
43 44 45 |
# File 'lib/migemo.rb', line 43 def dict_cache @dict_cache end |
#insertion ⇒ Object
Returns the value of attribute insertion.
42 43 44 |
# File 'lib/migemo.rb', line 42 def insertion @insertion end |
#optimization ⇒ Object
Returns the value of attribute optimization.
40 41 42 |
# File 'lib/migemo.rb', line 40 def optimization @optimization end |
#regex_dict ⇒ Object
Returns the value of attribute regex_dict.
45 46 47 |
# File 'lib/migemo.rb', line 45 def regex_dict @regex_dict end |
#type ⇒ Object
Returns the value of attribute type.
41 42 43 |
# File 'lib/migemo.rb', line 41 def type @type end |
#user_dict ⇒ Object
Returns the value of attribute user_dict.
44 45 46 |
# File 'lib/migemo.rb', line 44 def user_dict @user_dict end |
#with_paren ⇒ Object
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
#lookup ⇒ Object
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 |
#regex ⇒ Object
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_tree ⇒ Object
63 64 65 |
# File 'lib/migemo.rb', line 63 def regex_tree lookup end |