Class: Goodcheck::Location

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

Overview

In the example below, each attribute is:

  • start_line: 2

  • start_column: 3

  • end_line: 2

  • end_column: 9

Examples:


1 |
2 | A matched text
3 |   ^~~~~~~
      3456789

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, start_column:, end_line:, end_column:) ⇒ Location

Returns a new instance of Location.



22
23
24
25
26
27
# File 'lib/goodcheck/location.rb', line 22

def initialize(start_line:, start_column:, end_line:, end_column:)
  @start_line = start_line
  @start_column = start_column
  @end_line = end_line
  @end_column = end_column
end

Instance Attribute Details

#end_columnObject (readonly)

Returns the value of attribute end_column.



20
21
22
# File 'lib/goodcheck/location.rb', line 20

def end_column
  @end_column
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



19
20
21
# File 'lib/goodcheck/location.rb', line 19

def end_line
  @end_line
end

#start_columnObject (readonly)

Returns the value of attribute start_column.



18
19
20
# File 'lib/goodcheck/location.rb', line 18

def start_column
  @start_column
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



17
18
19
# File 'lib/goodcheck/location.rb', line 17

def start_line
  @start_line
end

Instance Method Details

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



37
38
39
40
41
42
43
# File 'lib/goodcheck/location.rb', line 37

def ==(other)
  other.is_a?(Location) &&
    other.start_line == start_line &&
    other.start_column == start_column &&
    other.end_line == end_line &&
    other.end_column == end_column
end

#column_sizeObject



33
34
35
# File 'lib/goodcheck/location.rb', line 33

def column_size
  end_column - start_column + 1
end

#hashObject



47
48
49
# File 'lib/goodcheck/location.rb', line 47

def hash
  self.class.hash ^ start_line.hash ^ start_column.hash ^ end_line.hash ^ end_column.hash
end

#one_line?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/goodcheck/location.rb', line 29

def one_line?
  start_line == end_line
end