Class: PmdTester::CollectionByFile
- Inherits:
-
Object
- Object
- PmdTester::CollectionByFile
- 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
- #[](fname) ⇒ Object
- #add_all(filename, values) ⇒ Object
- #all_files ⇒ Object
- #all_values ⇒ Object
- #each_value(&block) ⇒ Object
-
#initialize ⇒ CollectionByFile
constructor
A new instance of CollectionByFile.
- #num_files ⇒ Object
- #to_h ⇒ Object
- #total_size ⇒ Object
Constructor Details
#initialize ⇒ CollectionByFile
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_files ⇒ Object
29 30 31 |
# File 'lib/pmdtester/collection_by_file.rb', line 29 def all_files @hash.keys end |
#all_values ⇒ Object
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_files ⇒ Object
33 34 35 |
# File 'lib/pmdtester/collection_by_file.rb', line 33 def num_files @hash.size end |
#to_h ⇒ Object
51 52 53 |
# File 'lib/pmdtester/collection_by_file.rb', line 51 def to_h @hash end |
#total_size ⇒ Object
25 26 27 |
# File 'lib/pmdtester/collection_by_file.rb', line 25 def total_size @total end |