Class: ClassStructure

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

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ ClassStructure

Returns a new instance of ClassStructure.



2
3
4
# File 'lib/class_structure.rb', line 2

def initialize(code)
  @code = code
end

Instance Method Details

#collection_countObject



23
24
25
# File 'lib/class_structure.rb', line 23

def collection_count
  @code.scan(/\s+@\w+\s*\=\s*(\[.*?\]|\{.*?\}|Array\.new|Set\.new|Hash\.new)/).size
end

#has_accessor_method?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/class_structure.rb', line 14

def has_accessor_method?
  all_instance_variables = instance_variables
  method_names.any? {|method_name| instance_variables.include?(method_name.gsub('=',''))}
end

#instance_variablesObject



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

def instance_variables
  @code.scan(/\s+\@\w+/).map {|name| name.strip.sub('@','')}.uniq
end

#line_countObject



19
20
21
# File 'lib/class_structure.rb', line 19

def line_count
  @code.split("\n").reject{|line| line.strip.size==0}.size
end

#method_namesObject



10
11
12
# File 'lib/class_structure.rb', line 10

def method_names
  @code.scan(/def \w+/).map {|name| name.sub('def ','')}.uniq
end