Class: Gergich::FileReview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, inline) ⇒ FileReview

Returns a new instance of FileReview.



559
560
561
562
563
# File 'lib/gergich.rb', line 559

def initialize(path, inline)
  self.path = path
  self.comments = Hash.new { |hash, position| hash[position] = [] }
  self.inline = inline
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



557
558
559
# File 'lib/gergich.rb', line 557

def comments
  @comments
end

#inlineObject

Returns the value of attribute inline.



557
558
559
# File 'lib/gergich.rb', line 557

def inline
  @inline
end

#min_scoreObject

Returns the value of attribute min_score.



557
558
559
# File 'lib/gergich.rb', line 557

def min_score
  @min_score
end

#pathObject

Returns the value of attribute path.



557
558
559
# File 'lib/gergich.rb', line 557

def path
  @path
end

Instance Method Details

#add_comment(position, message, severity) ⇒ Object



565
566
567
568
569
# File 'lib/gergich.rb', line 565

def add_comment(position, message, severity)
  position = position.to_i if position =~ /\A\d+\z/
  comments[position] << "[#{severity.upcase}] #{message}"
  self.min_score = [min_score || 0, Draft::SEVERITY_MAP[severity]].min
end

#countObject



571
572
573
# File 'lib/gergich.rb', line 571

def count
  comments.size
end

#to_aObject



575
576
577
578
579
580
581
582
583
584
585
# File 'lib/gergich.rb', line 575

def to_a
  comments.map do |position, position_comments|
    comment = position_comments.join("\n\n")
    position_key = position.is_a?(Integer) ? :line : :range
    position = JSON.parse(position) unless position.is_a?(Integer)
    {
      :message => comment,
      position_key => position
    }
  end
end