Class: CodePoetry::Method

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, name, first_line, last_line, location) ⇒ Method

Returns a new instance of Method.



6
7
8
9
10
11
12
13
14
# File 'lib/code_poetry/method.rb', line 6

def initialize(node, name, first_line, last_line, location)
  @node              = node
  @name              = name
  @first_line        = first_line
  @last_line         = last_line
  @complexity        = 0
  @duplication_count = 0
  @location          = location.sub './', ''
end

Instance Attribute Details

#complexityObject

Returns the value of attribute complexity.



4
5
6
# File 'lib/code_poetry/method.rb', line 4

def complexity
  @complexity
end

#duplication_countObject

Returns the value of attribute duplication_count.



4
5
6
# File 'lib/code_poetry/method.rb', line 4

def duplication_count
  @duplication_count
end

#first_lineObject (readonly)

Returns the value of attribute first_line.



3
4
5
# File 'lib/code_poetry/method.rb', line 3

def first_line
  @first_line
end

#last_lineObject (readonly)

Returns the value of attribute last_line.



3
4
5
# File 'lib/code_poetry/method.rb', line 3

def last_line
  @last_line
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/code_poetry/method.rb', line 3

def name
  @name
end

#nodeObject

Returns the value of attribute node.



4
5
6
# File 'lib/code_poetry/method.rb', line 4

def node
  @node
end

Instance Method Details

#duplicated?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/code_poetry/method.rb', line 20

def duplicated?
  @duplication_count > 0
end

#increase_duplication_countObject



33
34
35
# File 'lib/code_poetry/method.rb', line 33

def increase_duplication_count
  @duplication_count =+ 1
end

#pretty_locationObject



29
30
31
# File 'lib/code_poetry/method.rb', line 29

def pretty_location
  "#{@location}:#{@first_line}..#{@last_line}"
end

#pretty_nameObject



24
25
26
27
# File 'lib/code_poetry/method.rb', line 24

def pretty_name
  symbol = @node == :def ? '.' : '#'
  "#{symbol}#{@name}"
end

#smelly?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/code_poetry/method.rb', line 16

def smelly?
  @complexity > 25
end