Class: PmdTester::CollectionByFile

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

Overview

A collection of things, grouped by file.

(Note: this replaces PmdErrors and PmdViolations)

Instance Method Summary collapse

Constructor Details

#initializeCollectionByFile

Returns a new instance of CollectionByFile.



8
9
10
11
12
# File 'lib/pmdtester/collection_by_file.rb', line 8

def initialize
  # a hash of filename -> [list of items]
  @hash = Hash.new([])
  @total = 0
end

Instance Method Details

#[](fname) ⇒ Object



47
48
49
# File 'lib/pmdtester/collection_by_file.rb', line 47

def [](fname)
  @hash[fname]
end

#add_all(filename, values) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/pmdtester/collection_by_file.rb', line 14

def add_all(filename, values)
  return if values.empty?

  if @hash.key?(filename)
    @hash[filename].concat(values)
  else
    @hash[filename] = values
  end
  @total += values.size
end

#all_filesObject



29
30
31
# File 'lib/pmdtester/collection_by_file.rb', line 29

def all_files
  @hash.keys
end

#all_valuesObject



37
38
39
# File 'lib/pmdtester/collection_by_file.rb', line 37

def all_values
  @hash.values.flatten
end

#each_value(&block) ⇒ Object



41
42
43
44
45
# File 'lib/pmdtester/collection_by_file.rb', line 41

def each_value(&block)
  @hash.each_value do |vs|
    vs.each(&block)
  end
end

#num_filesObject



33
34
35
# File 'lib/pmdtester/collection_by_file.rb', line 33

def num_files
  @hash.size
end

#to_hObject



51
52
53
# File 'lib/pmdtester/collection_by_file.rb', line 51

def to_h
  @hash
end

#total_sizeObject



25
26
27
# File 'lib/pmdtester/collection_by_file.rb', line 25

def total_size
  @total
end