Class: Goodcheck::Issue

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer:, rule:, text: nil, text_begin_pos: nil) ⇒ Issue

Returns a new instance of Issue.



8
9
10
11
12
13
14
# File 'lib/goodcheck/issue.rb', line 8

def initialize(buffer:, rule:, text: nil, text_begin_pos: nil)
  @buffer = buffer
  @rule = rule
  @text = text
  @range = text ? text_begin_pos..(text_begin_pos + text.bytesize - 1) : nil
  @location = nil
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



3
4
5
# File 'lib/goodcheck/issue.rb', line 3

def buffer
  @buffer
end

#rangeObject (readonly)

Returns the value of attribute range.



6
7
8
# File 'lib/goodcheck/issue.rb', line 6

def range
  @range
end

#ruleObject (readonly)

Returns the value of attribute rule.



4
5
6
# File 'lib/goodcheck/issue.rb', line 4

def rule
  @rule
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/goodcheck/issue.rb', line 5

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



32
33
34
35
36
37
# File 'lib/goodcheck/issue.rb', line 32

def ==(other)
  other.is_a?(Issue) &&
    other.buffer == buffer &&
    other.range == range &&
    other.rule == rule
end

#hashObject



41
42
43
# File 'lib/goodcheck/issue.rb', line 41

def hash
  self.class.hash ^ buffer.hash ^ range.hash ^ rule.hash
end

#locationObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/goodcheck/issue.rb', line 20

def location
  if range
    unless @location
      start_line, start_column = buffer.location_for_position(range.begin)
      end_line, end_column = buffer.location_for_position(range.end)
      @location = Location.new(start_line: start_line, start_column: start_column, end_line: end_line, end_column: end_column)
    end

    @location
  end
end

#pathObject



16
17
18
# File 'lib/goodcheck/issue.rb', line 16

def path
  buffer.path
end