Class: Detector

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

Overview

this class not surport override method, in future may fix it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Detector

Returns a new instance of Detector.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ModelGenerator/Detector.rb', line 7

def initialize(file_path)
   if File.exist?(file_path)
       file=File.new(file_path,"r")
       if file
           @content=file.read
       end
   end
   
   @methods_implement_hash = Hash.new
   @methods_name_implment_hash = Hash.new
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/ModelGenerator/Detector.rb', line 5

def content
  @content
end

#methods_implement_hashObject (readonly)

Returns the value of attribute methods_implement_hash.



3
4
5
# File 'lib/ModelGenerator/Detector.rb', line 3

def methods_implement_hash
  @methods_implement_hash
end

#methods_name_implment_hashObject (readonly)

Returns the value of attribute methods_name_implment_hash.



4
5
6
# File 'lib/ModelGenerator/Detector.rb', line 4

def methods_name_implment_hash
  @methods_name_implment_hash
end

Instance Method Details

#detect_methodObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ModelGenerator/Detector.rb', line 19

def detect_method
  if !@content then return end 
    
  method_regular=/^[+-].*\(.*\)[\s\S]*?(\w*)[\s\S]*?\n}/
  @content.gsub(method_regular).each do |method_implment|
    @methods_implement_hash[method_implment]= true
    method_name= $1
    @methods_name_implment_hash[method_name] = method_implment
    
  end

end

#get_method_name(method_implement) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/ModelGenerator/Detector.rb', line 33

def get_method_name(method_implement)
    name = ""
    name_regular= /[+-].*\(.*\)[\s\S]*?(\w*)[\s\S]*?}/  
    method_implement.gsub(name_regular).each do |method_name|
      name = $1
    end

    return name 
end

#method_implment_same?(method_implement) ⇒ Boolean

if same return false , else return file method implement the meanning of this method is not very suitable

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ModelGenerator/Detector.rb', line 45

def method_implment_same? (method_implement)
  if !methods_implement_hash then return end
  
  method_name=self.get_method_name(method_implement)
  file_method_implement= @methods_name_implment_hash[method_name]
  if file_method_implement
    if file_method_implement == method_implement
      return false
    else 
      return file_method_implement +"\n"
    end
  end
  
  return false
end