Class: RDist::Analyzer::Base

Inherits:
Object
  • Object
show all
Extended by:
Macros
Defined in:
lib/rdist/analyzer/base.rb

Direct Known Subclasses

MethodLength, NumLinesInClass, NumMethodsInClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern_open_token, pattern_count_target, pattern_close_token, allow_nesting, histogram_interval = 5) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rdist/analyzer/base.rb', line 8

def initialize(pattern_open_token, pattern_count_target,
               pattern_close_token, allow_nesting,
               histogram_interval=5)
  @pattern_open_token = pattern_open_token
  @pattern_count_target = pattern_count_target
  @pattern_close_token = pattern_close_token
  @allow_nesting = allow_nesting
  @histogram_interval = histogram_interval
  init_count()
  init_state_objects()
end

Instance Attribute Details

#histogram_interval=(value) ⇒ Object (writeonly)

Sets the attribute histogram_interval

Parameters:

  • value

    the value to set the attribute histogram_interval to.



23
24
25
# File 'lib/rdist/analyzer/base.rb', line 23

def histogram_interval=(value)
  @histogram_interval = value
end

#pattern_close_tokenObject (readonly)

Returns the value of attribute pattern_close_token.



22
23
24
# File 'lib/rdist/analyzer/base.rb', line 22

def pattern_close_token
  @pattern_close_token
end

#pattern_count_targetObject (readonly)

Returns the value of attribute pattern_count_target.



21
22
23
# File 'lib/rdist/analyzer/base.rb', line 21

def pattern_count_target
  @pattern_count_target
end

#pattern_open_tokenObject (readonly)

Returns the value of attribute pattern_open_token.



20
21
22
# File 'lib/rdist/analyzer/base.rb', line 20

def pattern_open_token
  @pattern_open_token
end

Instance Method Details

#__set_state_in_block__Object



77
# File 'lib/rdist/analyzer/base.rb', line 77

alias __set_state_in_block__ set_state_in_block

#add_count_of(block_name, line_id) ⇒ Object



59
60
61
62
63
# File 'lib/rdist/analyzer/base.rb', line 59

def add_count_of(block_name, line_id)
  block_id = "#{block_name} (at #{@path}:#{line_id})"
  @count_of[block_id] ||= 0
  @count_of[block_id]  += 1
end

#allow_nesting?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rdist/analyzer/base.rb', line 65

def allow_nesting?
  @allow_nesting
end

#analyze(path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rdist/analyzer/base.rb', line 33

def analyze(path)
  @path = path
  DebugLogger.debug "Analyzing ``#{@path}''"
  init_state()
  open(path, 'r') do |input|
    input.each_line do |line|
      @current_line_id = input.lineno
      analyze_line(line)
    end
  end
  @current_line_id = nil
  reset_state_objects()
end

#analyze_all(pathes) ⇒ Object



26
27
28
29
30
31
# File 'lib/rdist/analyzer/base.rb', line 26

def analyze_all(pathes)
  init_count()
  pathes.each do |path|
    analyze(path)
  end
end

#deny_nesting?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/rdist/analyzer/base.rb', line 69

def deny_nesting?
  not @allow_nesting
end

#histogramObject



47
48
49
# File 'lib/rdist/analyzer/base.rb', line 47

def histogram
  Histogram.new(@count_of, @histogram_interval)
end

#rankingObject



51
52
53
# File 'lib/rdist/analyzer/base.rb', line 51

def ranking
  Ranking.new(@count_of)
end

#resetObject



55
56
57
# File 'lib/rdist/analyzer/base.rb', line 55

def reset
  init_count()
end

#set_state_in_block(indent, block_name) ⇒ Object



79
80
81
82
83
# File 'lib/rdist/analyzer/base.rb', line 79

def set_state_in_block(indent, block_name)
  __set_state_in_block__()
  @state.push_to_stacks(indent, block_name,
                        @current_line_id)
end