Class: LintTrappings::Location
- Inherits:
-
Object
- Object
- LintTrappings::Location
- Includes:
- Comparable
- Defined in:
- lib/lint_trappings/location.rb
Overview
Store location of a Lint in a document.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(line = 1, column = 1) ⇒ Location
constructor
A new instance of Location.
- #to_s ⇒ Object
Constructor Details
#initialize(line = 1, column = 1) ⇒ Location
Returns a new instance of Location.
10 11 12 13 14 15 16 |
# File 'lib/lint_trappings/location.rb', line 10 def initialize(line = 1, column = 1) raise ArgumentError, "Line must be >= 0, but was #{line}" if line < 0 raise ArgumentError, "Column must be >= 0, but was #{column}" if column < 0 @line = line @column = column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
6 7 8 |
# File 'lib/lint_trappings/location.rb', line 6 def column @column end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
6 7 8 |
# File 'lib/lint_trappings/location.rb', line 6 def line @line end |
Instance Method Details
#<=>(other) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/lint_trappings/location.rb', line 26 def <=>(other) [:line, :column].each do |attr| result = send(attr) <=> other.send(attr) return result unless result == 0 end 0 end |
#==(other) ⇒ Object Also known as: eql?
18 19 20 21 22 |
# File 'lib/lint_trappings/location.rb', line 18 def ==(other) [:line, :column].all? do |attr| send(attr) == other.send(attr) end end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/lint_trappings/location.rb', line 35 def to_s "(#{line},#{column})" end |