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.



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

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.



568
569
570
# File 'lib/gergich.rb', line 568

def comments
  @comments
end

#inlineObject

Returns the value of attribute inline.



568
569
570
# File 'lib/gergich.rb', line 568

def inline
  @inline
end

#min_scoreObject

Returns the value of attribute min_score.



568
569
570
# File 'lib/gergich.rb', line 568

def min_score
  @min_score
end

#pathObject

Returns the value of attribute path.



568
569
570
# File 'lib/gergich.rb', line 568

def path
  @path
end

Instance Method Details

#add_comment(position, message, severity) ⇒ Object



576
577
578
579
580
# File 'lib/gergich.rb', line 576

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



582
583
584
# File 'lib/gergich.rb', line 582

def count
  comments.size
end

#to_aObject



586
587
588
589
590
591
592
593
594
595
596
# File 'lib/gergich.rb', line 586

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