Sha256: 2678af7077e08d93520ab0f33770628c868b2add3f2ac9b6ee13b2259c160104

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

# frozen_string_literal: true

class PmdFile
  require_relative "./pmd_violation"
  attr_accessor :file

  def initialize(file)
    @file = file
  end

  def source_path
    @source_path ||= file.attribute("name").value.to_s
  end

  def absolute_path
    dirname = File.basename(Dir.getwd)
    if source_path.index(dirname)
      index_start = source_path.index(dirname) + dirname.length + 1
    else
      index_start = 0
    end
    index_end = source_path.length
    @absolute_path ||= Pathname.new(source_path[index_start, index_end]).to_s
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danger-pmd-0.1.1 lib/pmd/pmd_file.rb
danger-pmd-0.1.0 lib/pmd/pmd_file.rb