Class: PmdFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pmd/entity/pmd_file.rb

Overview

Represent a PMD file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, file) ⇒ PmdFile

Returns a new instance of PmdFile.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pmd/entity/pmd_file.rb', line 19

def initialize(prefix, file)
  @file = file
  @absolute_path = file.attribute('name').value.to_s

  prefix += (prefix.end_with?(file_separator) ? '' : file_separator)
  @relative_path = if @absolute_path.start_with?(prefix)
                     @absolute_path[prefix.length, @absolute_path.length - prefix.length]
                   else
                     @absolute_path
                   end
end

Instance Attribute Details

#absolute_pathString (readonly)

An absolute path to this file

Returns:

  • (String)


12
13
14
# File 'lib/pmd/entity/pmd_file.rb', line 12

def absolute_path
  @absolute_path
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/pmd/entity/pmd_file.rb', line 7

def file
  @file
end

#relative_pathString (readonly)

A relative path to this file

Returns:

  • (String)


17
18
19
# File 'lib/pmd/entity/pmd_file.rb', line 17

def relative_path
  @relative_path
end

Instance Method Details

#violationsObject



31
32
33
34
35
# File 'lib/pmd/entity/pmd_file.rb', line 31

def violations
  @violations ||= file.xpath('violation').map do |pmd_violation|
    PmdViolation.new(pmd_violation)
  end
end